locked
Confused on GUIDs and how they work RRS feed

  • Question

  • I have a lookup field called "Sales Contact", but I am confused about the GUID retrieved. When I lookup a record and use the following line:

    var sales_contact = Xrm.Page.data.entity.attributes.get("new_sales_contact").getValue()[0].id;

    I get the following GUID: {E65BE9EB-2DD5-E211-A2B7-AC162DBE2488}

    But the record itself, has the following GUID: {E77E79C1-08DF-E211-A1B5-AC162DBE3FFE}

    Am I right in assuming that the first GUID is just to identify the lookup because it doesn't give me the GUID of the actual record. If so how can I get the GUID of the actual record?

    Friday, June 28, 2013 11:27 AM

Answers

  • For the actual record you are in:

    Xrm.Page.data.entity.getId();


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, June 28, 2013 11:39 AM
    Moderator
  • Hi,

    If you want Current RecordId then use below line.

    var CurrentRecordId=Xrm.Page.data.entity.getId();

    If you want Lookup Record Id then Use Either any one of below.

    Var LookupId= Xrm.Page.data.entity.attributes.get("new_sales_contact").getValue()[0].id;

    OR

    Var LookupId= Xrm.Page.getAttribute("new_sales_contact").getValue()[0].id;


    If it help to you then please click on mark as complete and Vote helpful.

    Thanks,

    sravan

    • Marked as answer by Sebd.DD Friday, June 28, 2013 12:07 PM
    Friday, June 28, 2013 12:02 PM

All replies

  • Try this 

    var lookupObject = Xrm.Page.getAttribute(“CRMLookupSchemaName”).getValue();
    lookupObject[0].name; // text of lookup
    lookupObject[0].id; // Guid of lookup

    Friday, June 28, 2013 11:35 AM
  • For the actual record you are in:

    Xrm.Page.data.entity.getId();


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, June 28, 2013 11:39 AM
    Moderator
  • Hi, thanks, so I did something like this:

    var lookupObject = Xrm.Page.getAttribute(“new_sales_contact”).getValue();
    lookupObject[0].name; // text of lookup
    lookupObject[0].id; // Guid of lookup

    and found that it didn't work.

    Friday, June 28, 2013 11:44 AM
  • Just, to explain, I am trying to get the GUID of the actual record in the lookup and not of the current record. 
    Friday, June 28, 2013 11:49 AM
  • Hi,

    If you want Current RecordId then use below line.

    var CurrentRecordId=Xrm.Page.data.entity.getId();

    If you want Lookup Record Id then Use Either any one of below.

    Var LookupId= Xrm.Page.data.entity.attributes.get("new_sales_contact").getValue()[0].id;

    OR

    Var LookupId= Xrm.Page.getAttribute("new_sales_contact").getValue()[0].id;


    If it help to you then please click on mark as complete and Vote helpful.

    Thanks,

    sravan

    • Marked as answer by Sebd.DD Friday, June 28, 2013 12:07 PM
    Friday, June 28, 2013 12:02 PM
  • Thanks guys worked great. 

    Also learnt to get current record GUID thanks to Jason.

    Friday, June 28, 2013 12:08 PM