web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error while passing GUID as parameters

(0) ShareShare
ReportReport
Posted on by

Hello everyone.

I have this requirement where I have to pass GUID as a parameter for filtering. But I am not able to execute the code. Could you tell me where I am making a mistake and how should I rectify it.

It is a web API query. 

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/systemusers?$select=firstname,fullname,new_originatingdepartment&$filter=systemuserId/Id eq (guid' " + name + " ')",true);

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Rushikesh Bhujbal Profile Picture
    285 on at

    1)No need to add "Guid" in api Call,

    2) web api will not understand "systemuserId", because it doesn't understand this format. all alphabets should be in lower case ie "systemuserid".

    The correct Url is this.

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/systemusers?$select=firstname,fullname,new_originatingdepartment&$filter=systemuserid eq " +guid,true);

    Remember : there is space between "systemuserid eq [guid]" . Don't forgot to add space befor "eq" and after "eq"

    For Details Ref : msdn.microsoft.com/.../mt607871.aspx

  • Community Member Profile Picture
    on at

    Thank you for your reply. But suppose I want to pass a variable which stores user id, where do I pass that.

    var name=Xrm.Page.context.getUserId();

  • Suggested answer
    BharatPremji Profile Picture
    2,485 on at

    Hi Darshani,

    You may need to do something like this:

    var name=Xrm.Page.context.getUserId();

    name = name.replace('{', '').replace('}', '');

    Bharat 

  • Suggested answer
    Rushikesh Bhujbal Profile Picture
    285 on at

    var name=Xrm.Page.context.getUserId();

    name = name.replace('{', '').replace('}', '');

    This will remove '{'  ,   '}' from retreived guid string.

  • Verified answer
    Community Member Profile Picture
    on at

    I tried but i am still getting error as bad request. After declaring var name and making the changes. Where do I pass the name variable on this line?

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/systemusers?$select=firstname,fullname,new_originatingdepartment&$filter=systemuserid eq " +guid,true);

  • Community Member Profile Picture
    on at

    Thank you so much! The code is finally up and working.

  • Rushikesh Bhujbal Profile Picture
    285 on at

    change "+guid" to your variable name "+name"

  • Community Member Profile Picture
    on at

    Hi Rushikesh,

    First of all thanks for all the help. You advice has come very much to use. I am new in this field and dont have much knowledge of MS CRM.

    I have a new requirement where the value of one field must autopopulate when I select a value in another lookup. For example I have two custom entities Member and Client which have an association with each other. When I select a value in the Member field, the Client field must autopopulate if there is only one client associated with the member, if there are more than one clients it must give me a list of all the related clients(similar to filetered lookups).

    I have written a code but have not got the desired output. If you could please help me with the same.

    function memberClient()

    {

    var entityName, entityId, entityLabel, lookupFieldObject;

    lookupFieldObject = Xrm.Page.data.entity.attributes.get('new_member');

    if (lookupFieldObject.getValue() != null)

    {

          entityId = lookupFieldObject.getValue()[0].id;

        entityId = entityId.replace('{', '').replace('}', '');

            entityName = lookupFieldObject.getValue()[0].entityType;

          entityLabel = lookupFieldObject.getValue()[0].name;

          alert(entityId);

          alert(entityName);

          alert(entityLabel);

    }

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_memberclientassociations?$select=_new_client_value&$filter=_new_member_value eq " + entityId, true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");

    req.onreadystatechange = function () {

      if (this.readyState === 4) {

          req.onreadystatechange = null;

           if (this.status === 200) {

              var results = JSON.parse(this.response);

               for (var i = 0; i < results.value.length; i++) {

                    var _new_client_value = results.value[i]["_new_client_value"];

                  var _new_client_value_formatted = results.value[i]["_new_client_value@OData.Community.Display.V1.FormattedValue"];

           alert(_new_client_value_formatted);

                    alert(_new_client_value);

                 var lookup = new Array();

                  lookup[0] = new Object();

                lookup[0].id = _new_client_value;

                lookup[0].name = _new_client_value_formatted;

                lookup[0].entityType = new_client;

                 Xrm.Page.getAttribute("new_client").setValue(lookup);

                  }

           }

           else {

               alert(this.statusText);

           }

       }

    };

    req.send();

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans