Hello everyone,
I'm working on a custom duration validator in Creatio, but I'm running into an issue where the function returns invalidMessage
before the validation logic completes.
Here’s a simplified version of my function:
durationValidator: function(){
var invalidMessage="";
var name=this.get("UsrNameLookup").value ?? null;
var currentDuration=this.get("UsrDurationMinute");
if(!name){
return;
}
var esqDuration = this.Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "UsrPerformances"
});
esqDuration.addColumn("UsrDurationMinute");
// var groupFilters = this.Ext.create("Terrasoft.FilterGroup");
var totalDuration = 0;
if(this.isAddMode()){
var nameFilter = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "UsrNameLookup", name);
// groupFilters.addItem(filterId);
esqDuration.filters.add("esqFirstFilter",nameFilter);
esqDuration.getEntityCollection(function(result) {
if (!result.success) {
this.showInformationDialog("Request error");
return;
} else {
result.collection.each(function(item) {
totalDuration += item.get("UsrDurationMinute");
}
);
}
totalDuration += currentDuration;
console.log(totalDuration);
this.Terrasoft.SysSettings.querySysSettingsItem("UsrMaximumDuration", function(maxDuration) {
// console.log("td"+totalDuration);
if (totalDuration > maxDuration) {
this.set("Numbervalue", false);
this.showInformationDialog("No more than " + maxDuration + " total performances duration is allowed.");
invalidMessage= "No more than " + maxDuration + " total performances duration is allowed.";
return{
invalidMessage: invalidMessage
};
}
else {
this.set("Numbervalue", true);
invalidMessage="";
return{
invalidMessage: invalidMessage
};
}
}, this);
}, this);
}else{
console.log("else");
var nameFilter = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "UsrNameLookup", name);
var idFilter = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.NOT_EQUAL, "Id", this.get("Id"));
esqDuration.filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;
esqDuration.filters.add("esqFirstFilter",nameFilter);
esqDuration.filters.add("esqSecondFilter", idFilter);
esqDuration.getEntityCollection(function(result) {
if (!result.success) {
this.showInformationDialog("Request error");
return;
} else {
result.collection.each(function(item) {
totalDuration += item.get("UsrDurationMinute");
}
);
// console.log("i am running");
// let prevduration=this.get("UsrprevDuration");
// console.log("previous duration"+ prevduration);
totalDuration += currentDuration;
}
console.log(totalDuration);
this.Terrasoft.SysSettings.querySysSettingsItem("UsrMaximumDuration", function(maxDuration) {
// console.log("td"+totalDuration);
if (totalDuration > maxDuration) {
this.set("Numbervalue", false);
this.showInformationDialog("No more than " + maxDuration + " total performances duration is allowed minutes.");
invalidMessage="No more than " + maxDuration + " total performances duration is allowed.";
return{
invalidMessage: invalidMessage
};
} else {
this.set("Numbervalue", true);
invalidMessage="";
return{
invalidMessage: invalidMessage
};
}
}, this);
}, this);
}
console.log(invalidMessage);
return{
invalidMessage: invalidMessage
};
},
The console.log(invalidMessage); statement always prints an empty string.
- The function returns
<strong>invalidMessage</strong>
before the asynchronous operations (getEntityCollection
and querySysSettingsItem
) complete.
- As a result, validation messages do not appear correctly.