Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Get regarding field value from a task in Dynamic CRM

Posted on by Microsoft Employee

Hi all,

I am a beginner to CRM dynamics.

I'm trying to get Regarding field in a task by API (Retrieve related entities for an entity by expanding navigation properties)

/api/data/v8.0/tasks?$select=*&$filter=statecode eq 0 and Microsoft.Dynamics.CRM.EqualUserId(PropertyName='ownerid')&$orderby=scheduledend desc&$top=10&$expand=_regardingobjectid_value($select=name)

I got a value from "_regardingobjectid_value" value when receiving a task but it said Bad Request for my request.

Do you have idea how to fix this?

Thanks,

Hon

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get regarding field value from a task in Dynamic CRM

    Thanks for your help. The important thing is: req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    It works

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get regarding field value from a task in Dynamic CRM

    Use it like this:

    var currentUserId = Xrm.Page.context.getUserId();

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/tasks?$select=_regardingobjectid_value&$filter=statecode eq 0 and  _ownerid_value eq "+ currentUserId + "&$orderby=scheduledend desc", 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 _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"];

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get regarding field value from a task in Dynamic CRM

    I want to get all tasks assigned to current user or specify user. I was able to get tasks by other Rest endpoint, just want to get regarding field (title) from tasks

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Get regarding field value from a task in Dynamic CRM

    What is this filter?

    Microsoft.Dynamics.CRM.EqualUserId(PropertyName='ownerid')

    I would suggest you to use this tool to build appi queries.

    github.com/.../releases

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans