Changes reflecting in payload but is not getting applied on target widget in workdetails page in casemanager 5.2.1 - dojo

In Workdetails page, under ‘Documents’ tab, when I set the alignment to ‘center’ from ‘right’ for the column value, its getting updated in payload but is not actually getting applied on target widget.
I have tried thru controller/Grid as well but its not getting set. Attached snap of same. A pointer in this regard would be of immense help.
Here is the snip:
var callbackFolderContent = function (resultset)
{
var classText = 'Abc';
var found = 0;
for (var i=0; i < resultset.length; i++)
{
var items = resultset[i].resultSet.items;
for (var j=0; j < items.length; j++)
{
var pos = id.indexOf(classText);
if(pos !== -1)
{
var PC= items[j].resultSet.structure.cells[0][3];
if(PC.styles=="text-align:right;")
{
PC.styles="text-align:center;";
var NEWpc=PC.styles; //Its reflecting in payload.
alert("Changed aligning to: "+NEWpc);
}
found ++;
} //end f if loop
} //end of inner for loop
} //end of for loop
if (found < 1)
{
payload.stateCode = 4;
payload.hideMessage=true;
abort({silent:true});
}
else
{
complete();
}
}; //end of callback function

Related

Change line spacing in a cell in a Google Doc using Google App Script

I have a Google Doc which has a table that needs updating weekly and content to be inserted from a spreadsheet. I successfully paste in the correct data into each cell but the lines are spaced at 1.15 not single spaced.
Any ideas on how to accomplish this?
Here is the code I have tried:
const doc = DocumentApp.getActiveDocument();
var paddingTop = 1.5; // You can adjust the height by modifying this.
var paddingBottom = 1.5; // You can adjust the height by modifying this.
var tables = doc.getBody().getTables();
tables.forEach(table => {
for (var r = 0; r < table.getNumRows(); r++) {
var row = table.getRow(r);
for (var c = 0; c < row.getNumCells(); c++) {
row.getCell(c).setPaddingTop(paddingTop).setPaddingBottom(paddingBottom);
var p=row.getCell(c);
Logger.log(c)
for(i=0;i<p.length; i++){
p[i].setLineSpacing(100);
}
}
}
});
This does not change the line spacing inside the cells at all.
This is what worked for me:
var paddingTop = 1.5; // You can adjust the height by modifying this.
var paddingBottom = 1.5; // You can adjust the height by modifying this.
var paraStyle = {};
paraStyle[DocumentApp.Attribute.LINE_SPACING] = 1;
var tables = doc.getBody().getTables();
tables.forEach(table => {
for (var r = 0; r < table.getNumRows(); r++) {
var row = table.getRow(r);
for (var c = 0; c < row.getNumCells(); c++) {
var cell=row.getCell(c);
cell.setPaddingTop(paddingTop)
cell.setPaddingBottom(paddingBottom);
var items = cell.getNumChildren();
for (var i = 0; i < items; i++){
var paraInCell = cell.getChild(i).asParagraph();
paraInCell.setAttributes(paraStyle);
}
}
}
});

Same variable for multiple sheets but only execute if export button on one sheet is pressed

I am trying to code an data export. The export is executed when a button is pressed and the script linked to the button will be executed. The data is transfered to a masterdata sheet.
The script is valid for 4 different sheets and i am trying to code it, so that i do not have to rename all the vaiables for each sheet.
I found some solution that i tried, by creating a variable with the sheet names and then call this variable in the following code.
Problem 1: Error "TypeError: Cannot read property 'copyTo' of null" occurs.
Problem 2: How to ensure that only the data from the sheet where the export button is pressed will be exported?
I tried a lot and cannot find a solution.
var sheetListArray = ["B1-Prozessfragen", "B2-Prozessfragen"];
var ss = SpreadsheetApp.getActiveSpreadsheet();
for( var k = 1 ; k <= sheetListArray.length ; k++)
ExportData1g (sheetListArray[k]);
PB1g (sheetListArray[k]);
function ExportData1g (sheetname) {
var result = SpreadsheetApp.getUi().alert("Fertig-Hacken gesetzt?", SpreadsheetApp.getUi().ButtonSet.OK_CANCEL); {
if (result === SpreadsheetApp.getUi().Button.OK) {
const ssh=ss.getSheetByName(sheetname);
const cell = ssh.getRange("CheckButton1").getValue();
if (cell == "1" || "0") {
(PB1g ());
}
else {return;} }
else {return;}
}
const ssh=ss.getSheetByName(sheetname);
var dataRange = ssh.getRange('CheckBox1');
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] == true) {
values[i][j] = false;
}}
dataRange.setValues(values);
var commentRange = ssh.getRange ('ResetComment1');
var dataRange = ssh.getRange('EmptyBoxes1');
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] == 1) {
values[i][j] = 0;
}
}
}
commentRange.clearContent();
dataRange.setValues(values);
} }
function PB1g(sheetname) {
const ssh=ss.getSheetByName(sheetname);
const tss=SpreadsheetApp.openById("1wMw5H48Fmc1R8WGy34d80x9-W996c9GNVuAD3-mFtVQ");
const tsh=tss.getSheetByName("PB");
const nsh=ssh.copyTo(tss);
var firstEmtyRow = tsh.getLastRow () + 1;
var timestamp = new Date();
tsh.appendRow([timestamp]);
nsh.getRange("CopytoMasterdata1").copyTo(tsh.getRange("B" + firstEmtyRow), {contentsOnly:true});
tss.deleteSheet(nsh); }

Adobe InDesign script to affect only selected Table/Text Frame

I am new to scripting and copied this one below and it works great but not all tables are the same in the document and I just want to affect the selected tables/text frames.
Is there an easy way to make this code work the way I am looking to do.
var myDoc = app.activeDocument;
var myWidths = [.5,.35,.44,.44];
for(var T=0; T < myDoc.textFrames.length; T++){
for(var i=0; i < myDoc.textFrames[T].tables.length; i++){
for(var j=0; j < myWidths.length; j++){
myDoc.textFrames[T].tables[i].columns[j].width = myWidths[j];
}
}
}
Thanks for any help, just starting to dive into InDesign Scripting and understand it.
Yes, it can be done quite easy:
var myWidths = [.5,.35,.44,.44];
var sel = app.selection;
if (sel.length != 1) exit();
var frame = sel[0];
if (frame.constructor.name != 'TextFrame') exit();
for (var i = 0; i < frame.tables.length; i++) {
for (var j = 0; j < myWidths.length; j++) {
frame.tables[i].columns[j].width = myWidths[j];
}
}
It will work for one selected text frame.
If you need to process several selected frames here is another variant of the code:
var myWidths = [.5,.35,.44,.44];
var frames = app.selection
var f = frames.length
while(f--) {
if (frames[f].constructor.name != 'TextFrame') continue;
var tables = frames[f].tables;
var t = tables.length;
while(t--) {
var table = tables[t];
var c = table.columns.length;
while(c--) {
table.columns[c].width = myWidths[c];
}
}
}

JSFL - Adding a movieclip to a specific layer and frame

I am trying to replace an outdated movieclip with a newer one.
To do this I'm usin JSFL to locate the old movieclips, save a reference, then add the new version in its place.
I have looked at addItem addItemToDocument and they successfully add the clip, but I'm unsure of how to add it to the specific layer and frame that the old instance of the movieclip was on.
Halps
Replacing all instances of the old movieclip with instances of the new movieclip, could be an easier solution.
All instances of the old movieclip can be found by parsing the timelines of the flash document.
Here is some code:
var _doc = (fl.getDocumentDOM() ? fl.getDocumentDOM() : fl.createDocument());
var _lib = _doc.library;
fl.outputPanel.clear();
ReplaceItemWithItem('Game Layouts/card holder', 'Game Layouts/card holder new');
function ReplaceItemWithItem(oldmcname, newmcname)
{
var item1 = GetItem(oldmcname);
var item2 = GetItem(newmcname);
if (!item1) return false;
if (!item2) return false;
if (oldmcname == newmcname)
return true;
return ReplaceAllItems(item1, item2);
}
function ReplaceAllItems(item1, item2)
{
var timelines = _doc.timelines;
var i, l = timelines.length;
var items = _lib.items;
var changed = false;
// Main timelines
for (i = 0; i < l; i++)
{
var timeline = timelines[i];
changed |= ReplaceItems(timeline, item1, item2);
}
// Timelines in library items
for (i = 0, l = items.length; i < l; i++)
{
var item = items[i];
switch (item.itemType)
{
case "movie clip":
case "graphic":
case "button":
changed |= ReplaceItems(item.timeline, item1, item2);
break;
}
}
return changed;
}
function ReplaceItems(timeline, item1, item2)
{
var changed = false;
if (timeline && item1 && item2)
{
var layers = timeline.layers;
var lay, layl = layers.length;
for (lay = 0; lay < layl; lay++)
{
var layer = layers[lay];
var frames = layer.frames;
var fr, frl = frames.length;
for (fr = 0; fr < frl; fr++)
{
var frame = frames[fr];
if (frame && frame.startFrame == fr)
{
var elements = frame.elements;
var e, el = elements.length;
for (e = 0; e < el; e++)
{
var elem = elements[e];
if (elem && elem.elementType == "instance") // Elements can be empty
{
var item = elem.libraryItem;
if (item.name == item1.name)
{
elem.libraryItem = item2;
changed = true;
}
}
}
}
}
}
}
return changed;
}
function GetItem(itemname)
{
if (!_lib.selectItem(itemname))
{
alert("'" + name + "' does not exist in the library!");
return null;
}
return _lib.getSelectedItems()[0];
}
Hope this helps!

InDesign copy layer to another document

I am trying to write a script that copies a layer from one document into another.
var srcDocName = 0;
var destDocName = 1;
var layerNameOriginal = "Original";
var layerNameCopyTo = "Destination";
var destDoc = app.documents.item(destDocName);
var layerSrc = app.documents.item(srcDocName).layers.item(layerNameOriginal);
try {
layerSrc.duplicate(destDoc, ElementPlacement.INSIDE);
}
catch(e) {
alert(e)
}
Apparently this works in Photoshop but not in InDesign. I have been trying for ages to find some decent documentation for InDesign scripting. But all I can find is the CS scripting guide, which isn't of much use.
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/indesign/pdfs/InDesignCS5_ScriptingGuide_JS.pdf
If someone can point me to a good reference to the object model I would be grateful.
After some more googling I finally found the answer:
var sourceLayer = app.documents[0].layers.itemByName("Layer1");
var destLayer = app.documents[1].layers[0];
sourceLayer.pageItems.everyItem().duplicate(destLayer);
I also came across jongware which seems to be a complete Object reference extracted directly out of Adobe CS.
You can use this script: https://redokun.com/blog/indesign-copy-entire-layer-one-file-another
The underlying implementation is basically the same, but we've added a UI so it's not necessary to edit the script every time the layer name changes.
Edit: We've been told that the solution above doesn't work with threaded text frames, so I re-wrote the script. The new implementation is way more complex but it now supports threaded TFs.
To expand on the solution offered by Loopo and offer you the ability to copy all layers from 1 document to another...
main();
function main()
{
var source = GetSourceDocument();
if(source == -1)
{
return;
}
var target = GetTargetDocument ();
if(target == -1)
{
return;
}
if(target == source)
{
return;
}
copyLayersOver(source, target);
}
function GetSourceDocument()
{
var returnVal = -1;
var oldPrefs = app.scriptPreferences.userInteractionLevel;
app.scriptPreferences.userInteractionLevel=UserInteractionLevels.INTERACT_WITH_ALL;
var dialog = app.dialogs.add({name:"Document to Copy From", canCanel: true, label:"DocumentToCopyFrom"});
var col1 = dialog.dialogColumns.add();
var StringList= [];
for(var i = 0; i<app.documents.length; i++)
{
StringList.push("[" + app.documents[i].index + "] " + app.documents[i].name);
}
var ddl = col1.dropdowns.add({id:"SourceDocDDL", stringList: StringList});
if(dialog.show() == true)
{
returnVal = ddl.stringList[ddl.selectedIndex].split("]")[0].substr(1);
}
else
{
returnVal -1;
}
dialog.destroy();
app.scriptPreferences.userInteractionLevel = oldPrefs;
return returnVal;
}
function GetTargetDocument()
{
var returnVal = -1;
var oldPrefs = app.scriptPreferences.userInteractionLevel;
app.scriptPreferences.userInteractionLevel=UserInteractionLevels.INTERACT_WITH_ALL;
var dialog = app.dialogs.add({name:"Document to Copy To", canCanel: true, label:"DocumentToCopyTo"});
var col1 = dialog.dialogColumns.add();
var StringList= [];
for(var i = 0; i<app.documents.length; i++)
{
StringList.push("[" + app.documents[i].index + "] " + app.documents[i].name);
}
var ddl = col1.dropdowns.add({id:"SourceDocDDL", stringList: StringList});
if(dialog.show() == true)
{
returnVal = ddl.stringList[ddl.selectedIndex].split("]")[0].substr(1);
}
else
{
returnVal -1;
}
dialog.destroy();
app.scriptPreferences.userInteractionLevel = oldPrefs;
return returnVal;
}
function copyLayersOver(source, target)
{
var sourceDocument = app.documents[source];
var targetDocument = app.documents[target];
var sourceLayers = sourceDocument.layers;
//Match the number of pages
while(targetDocument.pages.length < sourceDocument.pages.length)
{
targetDocument.pages.add();
}
//copy the layers over
for(var i= 0; i < sourceLayers.length; i++)
{
var names = targetDocument.layers.everyItem().name;
var merge = false;
for(var y = 0; y < names.length; y++)
{
if(names[y] == sourceLayers[i].name)
{
merge = true;
break;
}
}
if(merge)
{
var targetLayer = targetDocument.layers.add();
targetLayer.name = "temp";
sourceLayers[i].pageItems.everyItem().duplicate(targetLayer);
targetDocument.layers.itemByName(sourceLayers[i].name).merge(targetLayer);
}
else
{
var targetLayer = targetDocument.layers.add();
targetLayer.name = sourceLayers[i].name;
targetLayer.layerColor = sourceLayers[i].layerColor;
sourceLayers[i].pageItems.everyItem().duplicate(targetLayer);
}
}
}