web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to fetch the attributes of other entities using javascript

(0) ShareShare
ReportReport
Posted on by 35

Hi everyone 

The actual scenario is I have an entity for data mapping with an account, we had given the privilege to the user to create a new attribute 

depends upon the data they are importing 

as well I have two fields in the account if the two filed contains data I want to make read-only for all the attributes are related data mapping entity.

formContext.data.entity.attributes.get();
I am using the above the line of code to fetch the attributes of account and it's stored in an array 
as well I want to fetch the data of data map entity and I want to compare with the account attributes if both are same 
I want to lock it 
Thanks in advance 
I have the same question (0)
  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Since you have mapped some fields between your custom entity and account, you should know which fieds are mapped.

    And there should be a relationship between custom entity and account.

    So we chould resolve this requirement in this way.

    1.Check if the two fields contain data when onloading the account form.

    As you konw using "formContext.data.entity.attributes.get()" will get all the fields on the form, and if you want to get a special field's value, you could use the following code.

    pastedimage1577672137978v1.png

    We could use "find" method to find the special field we need with its field name.

    But there is a better way to get the field on the form, using "formContext.getAttribute()" could get the field directly and this method could also imporve the peformance cause it doesn't need to get all the fields on the form.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/getattribute

    2.Get the mapped field value in custom entity by web api.

    For example, if custom data entity has an 1:N relationship with account, so there should be a custom entity lookup field on the account entity.

    We could use the following code to get the related entity data by web api.

    var lookupObjB = Xrm.Page.getAttribute(lookupFieldName); //Check for Lookup Object
    if (lookupObjB != null) {
        var lookupObjValue = lookupObjB.getValue();//Check for Lookup Value
        if (lookupObjValue != null) {
            var lookupEntityTypeB = lookupObjValue[0].entityType//To get EntityName
                lookupRecordGuidB = lookupObjValue[0].id// To get record GUID
                lookupRecordNameB = lookupObjValue[0].name//To get record Name 
        }
    }



    Xrm.WebApi.retrieveRecord("EntityB",lookupRecordGuidB,"?$select=fieldnameA,fieldnameB,...").then(
        function success(result) {
            var fieldAInCustomEntity=result.fieldnameA;
            var fieldBInCustomEntity=result.fieldnameB;
            //..todo
        },
        function error(error) {
            Xrm.Navigation.openAlertDialog({ text: error.message });
        }
    );

    3.Compare the fields value and disable/enable the fields.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setdisabled

    Hope it helps.

    Best Regards,

    Leo

  • Verified answer
    ashish12 Profile Picture
    3,079 on at

    docs.microsoft.com/.../setdisabled

  • Eduteam srl Profile Picture
    35 on at

    Thanks its worked I used web Api retrieve multiple I was comparing more than one 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans