Hi Community,
I am facing an issue which is related to SectionActions Button for sending multiple records. I need to send some records (out of all selected records) to a business process in an array after filtering with esq inside section edit page.
Issue: The filtered Id's are not being pushed into array correctly. Means when we explore the array, the values are there but when we try to print or send we get initial value of that array (i.e. empty string or null).
getSectionActions: function() {
var actionMenuItems = this.callParent(arguments);
actionMenuItems.addItem(this.getButtonMenuItem({
Type: "Terrasoft.MenuSeparator",
Caption: ""
}));
actionMenuItems.addItem(this.getButtonMenuItem({
"Caption": {bindTo: "Resources.Strings.AMDAssignMultipleRecords"},
"Click": {bindTo:"runCustomProcess"},
"IsEnabledForSelectedAll": true
}));
return actionMenuItems;
},
runCustomProcess: function(){
if(this.get("SelectedRows") == "" || this.get("SelectedRows") == undefined){
this.showInformationDialog("Please select records for batch process!");
}
else{
var selectedRows = this.get("SelectedRows");
console.log("Selected records : ", selectedRows);
var recordsnumber = selectedRows.length;
var resIdRows=[];
var resIdForArray="";
selectedRows.forEach(fnProgramABCArray);
console.log("Selected ABC records : ", resIdRows);
var selectedOrder = resIdRows.toString();
console.log("selectedOrder: ", selectedOrder);
var args = {
sysProcessName: "AMDProcess_BatchAssignments",
parameters: {
SelectedRowsCol: selectedOrder,
NoOfRes: recordsnumber
},
};
ProcessModuleUtilities.executeProcess(args);
}
function fnProgramABCArray(item){
var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "AMDTestPlans" });
esq.addColumn("AMDStatus");
esq.addColumn("AMDProgram");
esq.filters.addItem(esq.createColumnFilterWithParameter(
Terrasoft.ComparisonType.EQUAL, "Id", item));
esq.getEntityCollection(function (result) {
let status = result.collection.getByIndex(0).get("AMDStatus").displayValue;
let program = result.collection.getByIndex(0).get("AMDProgram").displayValue;
if(status === "In Progress" && program === "ABC"){
resIdRows.push(item);
}
});
}
}
Please find attached screenshot below with an array of selected records vs another array of selected ABC records and string output as Selected order (empty string).
Like
Hi,
The issue here is that ESQ is asynchronous and as a result once the:
selectedRows.forEach(fnProgramABCArray);
is called, the browser continues executing the main runCustomProcess, but in addition executes the fnProgramABCArray in the background and when the
console.log("Selected ABC records : ", resIdRows);
and
console.log("selectedOrder: ", selectedOrder);
are executed they won't show anything, these will be an empty array and an empty string.
You need to modify this logic and perform the filtration of records in the business process directly where you can check all the records passed using either the read data element and the conditional flow or a script task that uses the SelectQuery class to check data consistency.
Best regards,
Oscar