Hello,

 

I need to make a button visible based on a few conditions

1. If current user contact record has a lookup value of "Approver"

and

2. If account record of the current user contact has lookup value "Enterprise"

 

Since there are 2 tables to be queried, I understand I need to use callbacks and chaining. This does not seem to work well for me. I have also tried passing a callback function within a callback function, but still its not working well. Can someone please give an example of multiple callbacks?

 

Thanks

Like 1

Like

2 comments

There's no need for the multiple callbacks since this can be done in a single ESQ query. For example, the ESQ below retrieves both the current user's Type value as well as the current user's account Type value in the same call.

var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
    rootSchemaName: "Contact"
});
 
esq.addColumn("Type");
esq.addColumn("Account.Type", "AccountType");
 
esq.getEntity(Terrasoft.SysValue.CURRENT_USER_CONTACT.value, function (result) {
    if (result.success) {
        var conType = result.entity.values.Type,
            accType = result.entity.values.AccountType;
 
        if ((conType && conType.displayValue == "Approver")
            && (accType && accType.displayValue == "Enterprise")) {
            // do something
        }
    }
}, this);

However, to nest a ESQ in a callback of another ESQ it would look like this: 

var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
	rootSchemaName: "Contact"
});
 
esq.addColumn("Type");
esq.addColumn("Account");
 
esq.getEntity(Terrasoft.SysValue.CURRENT_USER_CONTACT.value, function (result) {
    if (result.success) {
        var conType = result.entity.values.Type,
            account = result.entity.values.Account;
        if (conType && conType.displayValue == "Approver") {
            var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                rootSchemaName: "Account"
            });
 
            esq.addColumn("Type");
 
            esq.getEntity(account.value, function (result) {
                if (result.success) {
                    var accType = result.entity.values.Type;
                    if (accType && accType.displayValue == "Enterprise") {
                        // do something
                    }
                }
            }, this);
        }
    }
}, this);

Ryan

Show all comments