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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get the id of the entity.

(0) ShareShare
ReportReport
Posted on by 1,245

Hi,

  Can anyone help me that how to get the id of the entity by using the javascript. As I'm using MS Dynamics CRM 2011

Thanks,

Kamyaka

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    If you are on the same form and want to get record id, you can use below code simply

    Xrm.Page.data.entity.getId()

    and if you are in another entity and want to get record id you need to use retrievemultiple query where you can define your condition and get data from that entity and can read record id.

    Please download Ms CRM SDK you will see complete scripting reference there

  • Kasani Profile Picture
    1,245 on at

    Hi Mahender,

      As I'm using the below code to get the entity id, Can you please help me as i'm not getting the entity id.

    function GetRelated() {

    var context = Xrm.Page.context;

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

    var serverUrl = context.getServerUrl();

    var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

    var retrieveResult = new XMLHttpRequest();

    retrieveUserReq.open("GET", ODataPath + "/LeadSet(guid'" + EntityID + "')", true);

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

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

    retrieveResult.send();

    if (retrieveResult.readyState == 4 /* complete */) {

    if (retrieveResult.status == 200) {

    var retrieved= this.parent.JSON.parse(retrieveResult.responseText).d;

    var Result = retrieved.results[0];

    alert(Result.LeadId.results[0].Line1);

    window.open("xxxxxxxxxx" + Result.LeadId.results[0].DomainName, "_blank");

    }

    }

    }

    Thanks,

    Kasani

  • Kasani Profile Picture
    1,245 on at

    Hi Mahender,

      Sorry for the above code please find the updated code

     As I'm using the below code to get the entity id, Can you please help me as i'm not getting the entity id.

    function GetRelated() {

    var context = Xrm.Page.context;

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

    var serverUrl = context.getServerUrl();

    var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

    var retrieveResult = new XMLHttpRequest();

    retrieveUserReq.open("GET", ODataPath + "/LeadSet(guid'" + EntityID + "')", true);

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

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

    retrieveResult.send();

    if (retrieveResult.readyState == 4 /* complete */) {

    if (retrieveResult.status == 200) {

    var retrieved= this.parent.JSON.parse(retrieveResult.responseText).d;

    var Result = retrieved.results[0];

    window.open("xxxxxxxxxx" + Result.LeadId.results[0], "_blank");

    }

    }

    }

    Thanks,

    Kasani

  • Kasani Profile Picture
    1,245 on at

    As I'm in the same form

  • Mahendar Pal Profile Picture
    45,095 on at

    As I said in my earlier reply, if you could explain what you are trying to do, we can help you will complete setups,

    What you are trying to do here

    alert(Result.LeadId.results[0].Line1);  ??? what is line1 there is no field in lead with name of line1

    if you have any custom field, you need to use below format

    alert(Result.<<FieldSchemaname>>);

    Share your requirement

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    if you are in the same form you will get it using your above code

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

    why are you writing service call ??

  • Kasani Profile Picture
    1,245 on at

    Hi Mahender,

      As I'm trying to get the leadId in Url.

     As I don't have any custom fileld.

    Thanks,

    Kamyaka

  • Kasani Profile Picture
    1,245 on at

    I wrote the service call because on clicking the button it should open the window with url with LeadId.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    I still don't understand if you are in lead form itself why you want to open the same form again using ribbon button,  but if this is the only requirement you can simply write below code in your function that you can calling on ribbon button

    var EntityID = Xrm.Page.data.entity.getId(); //get current record id

    Xrm.Utility.openEntityForm("lead",EntityID); //open lead form with record id passed

  • Kasani Profile Picture
    1,245 on at

    As my requirement is on clicking the ribbon button on lead form it should open the window with fullname of the user and leadid of the particular lead which I have selected..

    Now I'm getting the fullname of user and unable to retrieve the leadid

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans