Hi Team,
I'm trying to set a caption for a field dynamically in onNotificationsLoad: function(isPageable, items) of ProcessDashboardSchema (this schema is replaced).
I'm iterating a collection and finding a value via ESQ and try setting the caption to a field but its not executing. Then, i tried to see the value in console, the main function doesn't wait for the internal function to complete though i had used the callback.
NOTE: Please find the attachment for reference.
Thanks in advance!
Regards,
Bhoobalan P.
attributes: {
"connectedRecordCaption": {
"dataValueType": this.Terrasoft.DataValueType.STRING,
"Value": "ConnetcedRecord"
},
},
methods:{
onNotificationsLoad: function(isPageable, items) {
var opportunityName = "sample";
this.console.log("from loadNotifications function");
items.eachKey(function(key, item) {
this.getConnectedRecordName(item,function(response){
var entityID = response;
if(entityID){
this.getOpportunityName(entityID,function(response){
opportunityName = response;
this.set("connectedRecordCaption",opportunityName); (Not Setting)
this.console.log(opportunityName);
},this);
}
},this);
}, this);
this.console.log("after loaded");
},
getConnectedRecordName : function(item,callback,scope){
//Logic to Fetch the entityID
var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "SysProcessEntity" });
esq.getEntityCollection(function (result) {
if (result.success && result.collection.getCount() > 0) {
var item = result.collection.getByIndex(0);
var entityId = item.get("EntityId");
callback.call(scope || this, entityId);
}
}, this);
},
getOpportunityName : function(entityId, callback,scope){
//Logic to Fetch the Opportunity Name
var esqActivity = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Activity" });
esqActivity.getEntityCollection(function (result) {
if (result.success && result.collection.getCount() > 0) {
var item = result.collection.getByIndex(0);
oppName = item.get("OpportunityName");
callback.call(scope || this, oppName);
}
}, this);
},
}
diff:[
{
"operation": "insert",
"name": "ConnectedRecord",
"parentName": "ConnectedRecordContainer",
"propertyName": "items",
"index": 1,
"values": {
"itemType": Terrasoft.ViewItemType.HYPERLINK,
//Resources.Strings.customCaption
"caption": {"bindTo": "connectedRecordCaption"},
"click": {"bindTo": "onConnectedRecordClick"},
"classes": {
"hyperlinkClass": ["title-text-labelClass"]
},
"canExecute": {"bindTo": "canBeDestroyed"}
}
},]
Like
Glancing through the code, nothing is standing out, however, based on your screenshot (at the expected result) and matching up with the code, the console.log("after loaded") will always execute before the results of the callback functions since it's outside of those.
I assume it's not setting your caption for the hyperlink? If that is the case, I'd start with making sure you're getting back the desired results from the ESQs in the callback functions (looks like you are based on the screenshot). Double-check to make sure all the code is inside the callbacks and not after. Worst case, you could move all the inline callback functions to actual functions and just call them from inside the ESQ callback.
Ryan
Hi Bhoobalan,
Additionally to Ryan's response you are using the "connectedRecordCaption" as an attribute in the schema. Maybe it would be easier to replace the SysProcessElementToDo object and add the connectedRecord column to the object and set the value for it using the onNotificationsLoad function as you did.
Best regards,
Oscar