Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Set the field value of one entity to another entity

Posted on by Microsoft Employee

I have 2 entities A and B with no entity relation between them . In the B entity i have a single line of text field .if i enter the value of the field in entity B it should compare with the field in entity A .if the value  matches it should set the value to another field of entity B .I am trying to do with JavaScript .but i don't know how to start .can anyone help on this

Thanks,

*This post is locked for comments

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Set the field value of one entity to another entity

    Hi Raja, You can do it with javascript and without relationship in these two entities ; however you have to have a field value in both of these entities which are similar and on the entity A you have create that field as an alternate key.

    now you have to retrieve the below :

    var entitybvalue = Xrm.Page.getAttribute(“entitybvalue”).getValue();

    var similarvalue = Xrm.Page.getAttribute(“similarvalue”).getValue();

    now do an webapi call :

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/entityA(alternatekeyonentityA='12345')?$select=valuefromentityA", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var result = JSON.parse(this.response);

               var mobilephone = result["valuefromentityA"];

    //do your comparison here and set the value to current entityB.

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    mark my suggestion as verified if helpful

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set the field value of one entity to another entity

    community.dynamics.com/.../262740

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/blogs/post/?postid=%27nvOpzp;%20AND%201=1%20OR%20(%3C%27%22%3EiKO))," - Too many )'s.