Set variable inside ESQ

Hi guys! 
question is about how to properly set variable inside esq classic ui:
getAccountId:function(callback, scope){

var caseId = this.get("MasterRecordId");

  var accountId = "";


 

  // GET ACCOUNT ID

  var esqCase = this.Ext.create("Terrasoft.EntitySchemaQuery", {

      rootSchemaName: "Case"

  });

  esqCase.addColumn("Account.Id","AccountId");

  esqCase.filters.add("AccountFiilter", Terrasoft.createColumnFilterWithParameter(

      Terrasoft.ComparisonType.EQUAL, "Id", caseId));

    esqCase.getEntityCollection(function(result) {

      if (result.success) {

          result.collection.each(function(item) {

              accountId = item.get("AccountId");

              callback.call(scope || this, accountId);

          });

      }

  }, this);

  // GET ACCOUNT ID

}


 

openBillingLineLookup: function() {

    var Terrasoft = this.Terrasoft;

    var caseId = this.get("MasterRecordId");

    var accountId = "";


 

       this.getAccountId(function(recordValue) {

        accountId  =  recordValue;

        console.log("account id",accountId);

    }, this);


 

  console.log("accountId after new func",accountId);// here is empty to due to async

}

 

Like 0

Like

2 comments

Hello Kamran,

 

Can you try rewriting the code and adding the Terrasoft.chain usage in it? As described here - https://community.creatio.com/articles/getentity-schema-works-asynchron….

Hi Kamran, 
What are you trying to achieve? 

If you just put the whole logic into the callback function, it'll work. 
Also you can wrap the esq call into a promise.

Show all comments