Set attribute on page from a related table

Hi all,

I am trying to display a field from a related table on a page.

I have 2 objects: Account and Contact. I've added a new integer field to Account called UsrScore.

I'd like to display the UsrScore field on the Contact page (based on an attribute).

I'm fairly certain I want to use EntitySchemaQuery but I can't find the correct syntax. Any help would be appreciated.

Nb. I'm not using the Freedom UI. 

Like 0

Like

1 comments

On the contact page, add an attribute to store the value from the account:

attributes: {
    "AccountScore": {
        dataValueType: Terrasoft.DataValueType.INTEGER
    }
}

Add onEntityInitialized in the methods where you'll retrieve the value from the account using the record's Account and store it in the attribute:

onEntityInitialized: function() {
    this.callParent(arguments);
 
    var account = this.get("Account");
 
    if (this.isAddMode() || !account) {
	    return;
    }
 
    var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
        rootSchemaName: "Account"
    });
    esq.addColumn("UsrScore");
    esq.getEntity(account.value, function (result) {
        if (result.success) {
            this.set("AccountScore", result.entity.values.UsrScore);
        }
    }, this);
}

Lastly, you'll need to add an element to the diff bound to the attribute to display it on the page. Easily way to do this is to drag something not currently on the page, like ModifiedOn, then find it in the diff and change the name and bindTo (make sure you set it as disabled):

{
    "operation": "insert",
    "name": "AccountScoreValue",
    "values": {
        "bindTo": "AccountScore",
        "enabled": false,
        // etc ...
    },
    "parentName": "SomeWhere",
    "propertyName": "items",
    "index": 0
}

Ryan

Show all comments