locked
Retrieve name from GUID RRS feed

  • Question

  • Hi,

    I am wondering if there is an easy way to retrieve other information about an entity once I have the GUID.

    I am very new to JavaScript but I have code on the onChange of a field which retrieves the GUID of another lookup field (which I am trying to populate). Now that I have the GUID, is there a way to get the name of the entity so I can populate the lookup field automatically?

    Thanks for any help!
    Friday, August 14, 2009 5:16 AM

Answers



  • Please download the MS CRM SDK if you haven't already. The sdk help file contains sample javascript code that you will find very helpful.

    The code below demonstrates how you can read the name and type of the record set in the lookup.
    var lookupItem = new Array;

    // This will get the lookup for the attribute primarycontactid on the Account form.
    lookupItem = crmForm.all.primarycontactid.DataValue;

    // If there is data in the field, show it in a series of alerts.
    if (lookupItem[0] != null)
    {
       // The text value of the lookup.
       alert(lookupItem[0].name);

       // The GUID of the lookup.
       alert(lookupItem[0].id);

       // The entity type name.
       alert(lookupItem[0].typename);
    }

    If you want data from other attributes you will need to use AJAX to query the db. You'll need the record GUID to query the DB. 
    You will need to make a call to either the MS CRM webservice by using a soap message or by passing fetchxml.

    The code below demonstrates how you can set a lookup.

    //Create an array to set as the DataValue for the lookup control.
    var lookupData = new Array();
    //Create an Object add to the array.
       var lookupItem= new Object();
    //Set the id, typename, and name properties to the object.
       lookupItem.id = '{1AAC1363-01A1-DB11-8432-0003FF9CE217}';
       lookupItem.typename = 'account';
       lookupItem.name = 'A Bike Store';
    // Add the object to the array.
       lookupData[0] = lookupItem;
    // Set the value of the lookup field to the value of the array.
       crmForm.all.parentaccountid.DataValue = lookupData;

    Note that both the code samples above are from the SDK help file.

    hope this helps. If you have questions about any of the above please feel free to post back.

    Hassan.





    Hassan Hussain | http://hassanhussain.wordpress.com/
    Friday, August 14, 2009 6:13 AM

All replies

  • Hi.

    You can use Retrieve message to retrieve this data via JavaScrpt and CRM webservices. Check this url .
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Proposed as answer by Jeff.Han Friday, August 14, 2009 8:39 AM
    Friday, August 14, 2009 5:50 AM
    Moderator


  • Please download the MS CRM SDK if you haven't already. The sdk help file contains sample javascript code that you will find very helpful.

    The code below demonstrates how you can read the name and type of the record set in the lookup.
    var lookupItem = new Array;

    // This will get the lookup for the attribute primarycontactid on the Account form.
    lookupItem = crmForm.all.primarycontactid.DataValue;

    // If there is data in the field, show it in a series of alerts.
    if (lookupItem[0] != null)
    {
       // The text value of the lookup.
       alert(lookupItem[0].name);

       // The GUID of the lookup.
       alert(lookupItem[0].id);

       // The entity type name.
       alert(lookupItem[0].typename);
    }

    If you want data from other attributes you will need to use AJAX to query the db. You'll need the record GUID to query the DB. 
    You will need to make a call to either the MS CRM webservice by using a soap message or by passing fetchxml.

    The code below demonstrates how you can set a lookup.

    //Create an array to set as the DataValue for the lookup control.
    var lookupData = new Array();
    //Create an Object add to the array.
       var lookupItem= new Object();
    //Set the id, typename, and name properties to the object.
       lookupItem.id = '{1AAC1363-01A1-DB11-8432-0003FF9CE217}';
       lookupItem.typename = 'account';
       lookupItem.name = 'A Bike Store';
    // Add the object to the array.
       lookupData[0] = lookupItem;
    // Set the value of the lookup field to the value of the array.
       crmForm.all.parentaccountid.DataValue = lookupData;

    Note that both the code samples above are from the SDK help file.

    hope this helps. If you have questions about any of the above please feel free to post back.

    Hassan.





    Hassan Hussain | http://hassanhussain.wordpress.com/
    Friday, August 14, 2009 6:13 AM
  • pls  call webservice  by javascript.


    you can see demo by mscrm sdk.



    my english is poor.

    I'm chinese!
    Eirc's Yang(杭州-天天) cnblog:http://www.cnblogs.com/ericqyang/ MSN:yqing630@hotmail.com
    Friday, August 14, 2009 6:35 AM