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

9 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

  3. Thanks, Andrew
    A colleague of mine was asking how he can access the fields from the embedded form component from the parent form and I forwarded the link of your blog post.

  4. Hi,

    I’ve two levels of form components, example Lead has account lookup, and form component for account. And on account, i’ve form component for primarycontact. Can you please suggest if there is a way to access primarycontact fields from lead main form JS ?

    Thank you.

  5. Hello Sir, Please i have a question , because now i have a pcf , and i deploy this pcf in a form of the table customer , and inside the pcf i want to get the customer name and customer number , but i don’t know how to use your code, could you please help me , this is my code :

    import { IInputs, IOutputs } from “./generated/ManifestTypes”;
    import * as React from ‘react’;
    import { Component } from “./Component”;
    import * as ReactDOM from ‘react-dom/client’;

    export class FileUpload implements ComponentFramework.StandardControl {
    private _container: HTMLDivElement;
    private _root: ReactDOM.Root | undefined;

    constructor() {
    // Empty
    }

    public init(
    context: ComponentFramework.Context,
    notifyOutputChanged: () => void,
    state: ComponentFramework.Dictionary,
    container: HTMLDivElement
    ): void {
    this._container = container;
    }

    public updateView(context: ComponentFramework.Context): void {
    if (!this._root) {
    this._root = ReactDOM.createRoot(this._container);
    }

    this._root.render(
    React.createElement(Component, { context })
    );
    }

    public getOutputs(): IOutputs {
    return {};
    }

    public destroy(): void {
    // no cleanup necessary
    }
    }

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.