Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Associate entities with web api using alternative keys

Posted on by Microsoft Employee

Is it possible to Associate entities with web api using alternative keys?

Something like:

POST [Organization URI]/api/data/v8.1/accounts HTTP/1.1
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json

{
"name":"Sample Account",
"primarycontactid@odata.bind":"/contacts(ALTERNATIVE_KEY)"
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Associate entities with web api using alternative keys

    Hi Uriy,

    Thanks for posting this.  Could you show how you would proceed with this if you wanted to associate all contact with accounts with matching alternate key?

    For example=

    All( Contacts(alternate_key=1) ) associate with Accounts(Accountnumber=1)

    Kind regards,

    -Lars

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Associate entities with web api using alternative keys

    Okay, i figured it out by myself:

    function createWithAKey() {

       debugger;

       try {

           var clientUrl = Xrm.Page.context.getClientUrl();

           var req = new XMLHttpRequest();

           req.open("POST", encodeURI(clientUrl + "/api/data/v8.0/kc_legal_entities"), true);

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

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

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

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

           req.onreadystatechange = function () {

               if (this.readyState == 4 /* complete */) {

                   req.onreadystatechange = null;

                   debugger;

                   if (this.status == 204) {

                   }

               }

           };

           var body = '{' +

           '"kc_name":"Test 2",' +

           '"kc_accountid@odata.bind":"/accounts(04F780FE-3265-E611-80CC-0025900A4E7D)",'+

           '"kc_countryid@odata.bind":"/kc_countries(kc_country_code=\'40\')"' +

       '}';

           req.send(body);

       } catch (e) {

       }

    }

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans