If you have the need to discover information about the current page in a generic manner, for cases where you might have a custom base page type that could be used for several different entity objects, the following will help you determine the schema information about the current page’s primary data source.
Getting the Page’s Primary Data Source
The first step in getting the bound schema/object information for the current page is to first get it’s primary data source. The primary data source will allow us to dig deeper to get the object information for that data source. On many out of the box pages, the primary data source is named PDS, but it could, and often is, named anything (especially on custom pages). You can get the primary data source using the function below:
const pds = await request.$context.getPrimaryModelName();
Getting the Schema Information for the Data Source
With the data source name, you can now get the schema information for the datasource which will give you the entity/object name, the Id column attribute, and also the primary display value attribute using the following (note, this gets the attribute names, not the values):
const pds = await request.$context.getPrimaryModelName(); const schema = await request.$context.dataSchemas[pds]; const entityName = await schema.name; const idColumn = await schema.primaryAttributeName; const nameColumn = await schema.primaryDisplayAttributeName;
The code above will retrieve the primary data source for the page, then use that to get the data schema. Note, for the idColumn and nameColumn variables above, they will end up with the attribute name that the column is bound to. So it might be something like nameColumn of “UsrCustomObject_UsrTitle_ssdkjxl” instead of the actual column name like “UsrTitle”. This will be useful to get the values for the bound page from these attributes.
Getting the Values for the Current Bound Object
Now that you have the attribute names for things like the primary Id column and the object’s primary display column, you can get the values from those attributes:
const idValue = await request.$context[idColumn]; const nameValue = await request.$context[nameColumn];
Conclusion
This sort of thing works great if you have a custom base page type that could be used for many different pages/objects, or if you have a custom override of a base Freedom UI page template that you won’t know ahead of time what the object using the template will be.
Also, as a FYI, not sure how this is going to change after Creatio 8.2.3. Creatio 8.2.3 has a beta feature (not enabled out of the box) that allows a page to have multiple connected data sources. That could potentially break some of this.



