In Freedom UI, how to select the data from the joined table in Model Class.
Hi Community,
In Freedom UI, how to select the data from the joined table in Model Class.
The code below is working fine; I am able to retrieve the values of the following, which are the fields of the main table.
"Id", "Name", "Type"
However, I am not able to retrieve the below, which is the fields of the joined table.
Account.UsrAddress
this is the full code
const contactModel = await
sdk.Model.create("Contact");
// define filter for Type = Partner
const filters = new
sdk.FilterGroup();
await
filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Id", contactId);
// now load the records and provide the filters
const contactData = await
contactModel.load({
attributes: ["Id", "Name", "Type", "Account.UsrAddress"],
parameters: [{
type: sdk.ModelParameterType.Filter,
value: filters
}]
});
Like
To access properties from related tables, the property name will be the entire string. Since the property name has a "." you need to access them as their string names.
For properties on the object itself you can use:
const typeVal = contactData[0].Type;
However, to access "Account.UsrAddress" you'd use:
const addrVal = contactData[0]["Account.UsrAddress"];
Ryan