Question

Pulling Data With ESQ Problem

Hello, I am testing out the entity schem query functions, and trying to pull some data into an message boxes. But if doesn't seem to be working, I just get an empty message box.

This is the code I have running in a method in the Account Page configuration.

        var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                  rootSchemaName: "Contact"
            });
    
            esq.addColumn("Account.Name", "AccountName");
        
            esq.addColumn("Account.PrimaryContact.Name", "PrimaryContactCity");

            esq.addColumn("Account.City", "PrimaryContactCity");

            var getid = this.get("Id");
            esq.getEntity(getid, function (result) {
              if (!result.success) {
                      
                       
                  this.showInformationDialog("Data query error");
                 return;
                 }
                else {
                
                    
                    var contact = esq.getEntity("PrimaryContactName");
                    var city = esq.getEntity("PrimaryContactCity");
                
                    this.showInformationDialog(contact);
                    this.showInformationDialog(city);
                
        
    }
   
}, this);

Like

2 comments

There's a few typos in your code. First, you alias both the Account.PrimaryContact.Name and Account.City both as "PrimaryContactCity".

Second, the lines: 

var contact = esq.getEntity("PrimaryContactName");
var city = esq.getEntity("PrimaryContactCity");

Should be: 

var contact = result.entity.values.PrimaryContactName;
var city = result.entity.values.PrimaryContactCity.displayValue;

FYI, you're likely getting an error in the browser console. If you open dev tools in your browser you'll see that error (probably something like "Guid should contain 32 digits..." since it's expecting the first param for getEntity to be a guid, this is fixed with the changes I outlined above).

Dear Nick,

Please see the example below of an ESQ. I have added comments, so to explain step-by-step work with ESQ.

		methods: {
//I have triggered my ESQ function when page initializes, however you are free to trigger it by any other means.
			onEntityInitialized: function() {
				this.callParent(arguments);
				this.showContactInfo();
			},
 
			showContactInfo: function() {
//I retrieve an Id of contact from the record.
				var primaryContact = this.get("Contact").value;
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
//create a query to Contact object
					rootSchemaName: "Contact"
				});
//indicate columns of Contact object. There is no need to give them alias, just indicate the name of columns.
				esq.addColumn("Name");
				esq.addColumn("City");
// add filters for the query, since if you won't filter records, you will receive all cities and names from contact object. I have filtered by contact id retrieved int he beginig of the function
				esq.filters.add(esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id", primaryContact));
				esq.getEntityCollection(
					function(result) {
						if (result.success) {
//assigning collection to the variable
							var items = result.collection.getItems();
//check whether we have received any record. Here you can add else statement for cases when no data is returned
							if (items && items.length > 0) {
//assigning received values to variables
								var name = items[0].values.Name;
								var city = items[0].values.City.displayValue;
//passing values to modal box, which is displayed to the user
								this.showInformationDialog("This is" + name + " who lives in city " + city);
							}
						}
					}, this);
			}

Hope you will find it helpful.

Regards,

Anastasia

Log in or register to comment