Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Retrieve 1:N relationships with javascript dynamics 365 crm

Posted on by Microsoft Employee

For example, I have a Case and some activities, which are related. How can I get the information from this activities, when case form is onload?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Retrieve 1:N relationships with javascript dynamics 365 crm

    Hi Lyubo,

    great!

    Could you please mark the answers as verified? Thanks a lot!

    Regards,

    Karan

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Retrieve 1:N relationships with javascript dynamics 365 crm

    I did it because of your answers. I am really thankful to all of you.

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Retrieve 1:N relationships with javascript dynamics 365 crm

    Hi,

    See the link below.

    msdn.microsoft.com/.../gg334208.aspx

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Retrieve 1:N relationships with javascript dynamics 365 crm

    Use CRMRestBuilder tool to get activities on case:

    github.com/.../releases

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/activitypointers?$select=actualend,actualstart,_regardingobjectid_value,scheduledend,scheduledstart,senton,statecode,statuscode&$filter=_regardingobjectid_value eq'" +Xrm.Page.data.entity.getId()+"'", 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 results = JSON.parse(this.response);

               for (var i = 0; i < results.value.length; i++) {

                   var actualend = results.value[i]["actualend"];

                   var actualstart = results.value[i]["actualstart"];

                   var _regardingobjectid_value = results.value[i]["_regardingobjectid_value"];

                   var _regardingobjectid_value_formatted = results.value[i]["_regardingobjectid_value@OData.Community.Display.V1.FormattedValue"];

                   var _regardingobjectid_value_lookuplogicalname = results.value[i]["_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

                   var scheduledend = results.value[i]["scheduledend"];

                   var scheduledstart = results.value[i]["scheduledstart"];

                   var senton = results.value[i]["senton"];

                   var statecode = results.value[i]["statecode"];

                   var statecode_formatted = results.value[i]["statecode@OData.Community.Display.V1.FormattedValue"];

                   var statuscode = results.value[i]["statuscode"];

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Retrieve 1:N relationships with javascript dynamics 365 crm

    It will be also helpful if you can give me some more detail on that what you want to do.

    Do you need to aggregate the records? Some status of the records? Waht exactly is the target?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Retrieve 1:N relationships with javascript dynamics 365 crm

    Check this out:

    msdn.microsoft.com/.../gg334427(v=crm.7).aspx

    Regards,

    Karan

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans