It’s often required to get the default tagprefix of an organization dynamicaly using REST endpoint.
We can get the default tagprefix from Default Publisher.But to know which is Default Publisher we need to get the DefaultSolution.
The following code snippet helps us to find the default tagprefix.
//Get the default TagPrefix of the Organization var filter = "UniqueName eq 'Default'"; var DefaultSolution = GetDefaultSolution("SolutionSet", filter, null, null, null); var Publisher = GetDefaultPublisher("PublisherSet", DefaultSolution.results[0].PublisherId.Id, null, null); var TagPrefix = Publisher.CustomizationPrefix; The function to get Default solution and Default publisher are as follows. function GetDefaultSolution(odataSetName, filter, successCallback, errorCallback) { var serverUrl = “http://localhost:5555”;//Enter your server url var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; //Build the URI var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName; //If a filter is supplied, append it to the OData URI if (filter) { odataUri += filter; } //Asynchronous AJAX function to Retrieve CRM records using OData $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: odataUri, beforeSend: function (XMLHttpRequest) { //Specifying this header ensures that the results will be returned as JSON. XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { if (successCallback) { if (data && data.d && data.d.results) { successCallback(data.d.results, textStatus, XmlHttpRequest); } else if (data && data.d) { successCallback(data.d, textStatus, XmlHttpRequest); } else { successCallback(data, textStatus, XmlHttpRequest); } } }, error: function (XmlHttpRequest, textStatus, errorThrown) { if (errorCallback) errorCallback(XmlHttpRequest, textStatus, errorThrown); else errorHandler(XmlHttpRequest, textStatus, errorThrown); } }); } function GetDefaultPublisher( odataSetName,id, successCallback, errorCallback) { var serverUrl = “http://localhost:5555”;//Enter your server url var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; //Asynchronous AJAX function to Retrieve a CRM record using OData $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')", beforeSend: function (XMLHttpRequest) { //Specifying this header ensures that the results will be returned as JSON. XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { if (successCallback) { successCallback(data.d, textStatus, XmlHttpRequest); } }, error: function (XmlHttpRequest, textStatus, errorThrown) { if (errorCallback) errorCallback(XmlHttpRequest, textStatus, errorThrown); else errorHandler(XmlHttpRequest, textStatus, errorThrown); } }); }
Note: Include json2 and jquery.1.4.4.min files.