UrbanPro
true

Learn MS Dynamics CRM from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How to use FetchXml in CRM Web API

Jayakar Reddy
13/06/2018 0 0

Here I am going to show how to use FetxhXML query to get the results from CRM Web API.  below example shows how to get logged in user Security roles.

function getRoles(token) {
var req = new XMLHttpRequest();
var fetch = “<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’true’>” +
“<entity name=’role’>” +
“<attribute name=’name’ />” +
“<attribute name=’businessunitid’ />” +
“<attribute name=’roleid’ />” +
“<order attribute=’name’ descending=’false’ />” +
“<link-entity name=’systemuserroles’ from=’roleid’ to=’roleid’ visible=’false’ intersect=’true’>” +
“<link-entity name=’systemuser’ from=’systemuserid’ to=’systemuserid’ alias=’ad’>” +
“<filter type=’and’>” +
“<condition attribute=’systemuserid’ operator=’eq-userid’ />” +
“</filter>” +
“</link-entity>” +
“</link-entity>” +
“</entity>” +
“</fetch>”;
$.ajax({
type: “GET”,
contentType: “application/json; charset=utf-8”,
datatype: “json”,
url: Xrm.Page.context.getClientUrl() + “/api/data/v8.2/roles?fetchXml=” + fetch,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader(“OData-MaxVersion”, “4.0”);
XMLHttpRequest.setRequestHeader(“OData-Version”, “4.0”);
XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
XMLHttpRequest.setRequestHeader(“Prefer”, “odata.include-annotations=\”*\””);
},
async: false,
success: function (data, textStatus, xhr) {
var results = data;
for (var i = 0; i < results.value.length; i++) {
var roleid = results.value[i][“roleid”];
var roleName = results.value[i][“name”];
}
},
error: function (xhr, textStatus, errorThrown) {
alert(textStatus + ” ” + errorThrown);
}
});
}

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Plugins In Microsoft Dynamics CRM
Microsoft Dynamics CRM plug-ins are one of the most commonly used and powerful approaches to extending the application. A plug-in for CRM is custom code, written and compiled in .Net, that is “triggered”...

Architecture of Business Process Flow in Dynamics 365
Business Process Flows till CRM 2016 Every record with Business process flow till Microsoft Dynamics 2016 , used to have two attributes specific to them:- Process ID : Process Stage ID. To set a desired...

CREATE a record using Web API, MS CRM 2016
Here is a link to my blog post with an example of using Web API to create a record: https://mscrmcodesamples.wordpress.com/2016/04/11/create-record-using-web-api-ms-crm-2016/

SLA in Microsoft Dynamics CRM 2016
Enhanced SLA Extended for Other Entities in Dynamics CRM 2016 Update 1 Introduction: In earlier versions of CRM, the SLA feature was only applied to the Case Entity. Now, with Dynamics CRM 2016 Update...
A

Anand

1 0
0

Business Rules in Dynamics 365
Business Rules and Their Components in Dynamics 365 Introduction to Business Rules in Dynamics 365 Hello, Dynamics 365 Enthusiasts! 🌟 Today, we’re diving into an exciting topic: Business Rules....

Looking for MS Dynamics CRM Training?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for MS Dynamics CRM Classes?

The best tutors for MS Dynamics CRM Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn MS Dynamics CRM with the Best Tutors

The best Tutors for MS Dynamics CRM Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more