none
CRM 2011 How can i get the Default Queue of a user by using Javascript REST...

    Question

  • 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


    Thursday, March 01, 2012 2:33 PM

Answers

  • 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)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Marked as answer by gonadn Friday, March 02, 2012 2:42 PM
    Thursday, March 01, 2012 5:28 PM
  • 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);
        }

    • Marked as answer by gonadn Friday, March 02, 2012 2:43 PM
    Friday, March 02, 2012 2:42 PM

All replies

  • 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)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Marked as answer by gonadn Friday, March 02, 2012 2:42 PM
    Thursday, March 01, 2012 5:28 PM
  • 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);


                        }
                    });




        }

    Friday, March 02, 2012 9:51 AM
  • 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);
        }

    • Marked as answer by gonadn Friday, March 02, 2012 2:43 PM
    Friday, March 02, 2012 2:42 PM