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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get regarding field value from a task in Dynamic CRM

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • Community Member Profile Picture
    on at

    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

  • Verified answer
    Community Member Profile Picture
    on at

    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
    on at

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

    It works

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans