Today during one of the work sessions with my colleague I found an interesting feature – it’s possible to access/work with related entity fields that are shown using “Form Component”. According to the documentation of “Form Component”, it’s possible but I was not able to locate any examples of it so if you’re curious how it could be performed check the following code:
Let’s say I’m on the “Account” form and I have the “Primary Contact” field configured using “Form Component”:
In order to access fields from the “Form Component” controls, it’s possible to use the following script:
1 2 3 4 5 6 7 8 9 10 11 12 |
function someEventHandler(executionContext){ var formContext = executionContext.getFormContext(); //this value defines if the control was already loaded var wasContentLoaded = formContext.getControl("primarycontactid1").isLoaded(); //getting value from First Name field var primaryContactFieldName = formContext.getControl("primarycontactid1").data.entity.attributes.get("firstname").getValue(); //changing the value of First Name field formContext.getControl("primarycontactid1").data.entity.attributes.get("firstname").setValue("Updated Name"); } |
Note: because it’s possible to place the same attribute of the form multiple times it would be required to use the proper index at the end of the control name – in my case I had attribute placed twice (first as regular lookup control – primarycontactid and the second time as a form component control – primarycontactid1).