Blog

JS: Access values of fields located on the “Form Component” PCF Control

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:

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).

3 Comments

  1. Hi,
    I am currently utilizing a form component control within a tab in CRM forms. I have a situation where, upon a status change in one tab, the fields in the second tab automatically disabled when it is opened.

    Could you please advise on how to implement the disabling of the form component control fields in this context?

    I used this code. it is not working. thank you, Siva
    var formcontrol = formContext.getControl(“apms_technicaldataid4”);
    formcontrol.data.entity.attributes.forEach(attribute => {
    var attributename = attribute.getName();
    if ( attribute.getName() !== “” && attribute.getName() !== null
    && attribute.getName() !== disableIndicatorField && attribute.getName() !== additionalField)
    {
    control.setDisabled(true);
    }
    });

  2. formcontrol.data.entity.attributes.forEach(attribute => {
    attribute.controls.forEach(control => {control.setDisabled(false);
    }

    i was able to resolve it with this code

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.