CRM 2011 How can i get the Default Queue of a user by using Javascript REST...
-
1. března 2012 14:33
Hi
How can i get Default queue of a User in CRM 2011 by using a javascript?
I am searching on google, but dident find any solution...!
regards
Všechny reakce
-
1. března 2012 17:28Moderátor
Hello,
Here is OData request that you can use - /xrmservices/2011/OrganizationData.svc/SystemUserSet?$select=QueueId&$filter=SystemUserId eq guid'DA278DC0-0C16-E111-92F2-1CC1DEE89ABF'
Of course you should replace provided id with identifier of your user.
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)
- Označen jako odpověď gonadn 2. března 2012 14:42
-
2. března 2012 9:51
Hi Andrii
Thanks for replaying ;)
Oki, but something is still wrong in my javascript, i get an error:
And here is my javascript:
function GetDefaultQueue(userId) {
//Get GUID of logged user
var user = Xrm.Page.context.getUserId();
var userId = user.substring(1, 37);
// Read the CRM Context to determine the CRM URL
var serverUrl = Xrm.Page.context.getServerUrl()
//var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var ODATA_ENDPOINT = "/xrmservices/2011/OrganizationData.svc/SystemUserSet?$select=QueueId&$filter= '" + userId + "'";
var ODATA_EntityCollection = "/SystemUserSet";
// Specify the ODATA Query
var ODATA_Query = "(guid\'" + userId + "')";
// Combine into the final URL
var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;
//Calls the REST endpoint to retrieve data
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: ODATA_Final_url,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
var userName = data.d.FullName;
alert(userName);
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert('Error: ' + ODATA_Final_url);
}
});
} -
2. března 2012 14:42
Here is my function for getting queue name:
function GetDefaultQueue() {
//Get GUID of logged user
var userId = Xrm.Page.context.getUserId();
SDK.REST.retrieveMultipleRecords("SystemUser", "$select=QueueId&$filter=SystemUserId eq guid'" + userId + "'",
function (results) {
var firstResult = results[0];
if (firstResult != null) {
var queueId = results[0].QueueId.Id;
var queueName = results[0].QueueId.Name;
var queueLogicalName = results[0].QueueId.LogicalName; //dette returnerer queue
}
// do your thing
alert(queueLogicalName);
}
}
function errorHandler(error) {
alert(error.message);
}- Označen jako odpověď gonadn 2. března 2012 14:43