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

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/

Dialog Runbase Example in AX 2012
class Runbase_Example extends RunBase{TransDate fromDate,toDate;CustAccount custAccount;DialogField dlgFromDate,dlgToDate,custDldField;#define.CurrentVersion(1)#localmacro.CurrentListfromDate,toDate#endmacro}protected...
S

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”...

Creating/Setting/Admin Center of Dynamics CRM - Office 365
Introduction Dynamics 365 is a cloud service launched by Microsoft. It combines its Cloud CRM and ERP services into a single offering.Microsoft Dynamics 365 is the next generation of intelligent business...

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...

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