Skip to main content

Notifications

Announcements

No record found.

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

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Get the id of the entity.

    I will appreciate if you will close all of your thread, so that it can others. Thanks

  • Kasani Profile Picture
    Kasani 1,245 on at
    RE: Get the id of the entity.

    Hi Mahender,

      Thanks for your help. I got it.

    Thanks,

    Kasani

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Get the id of the entity.

    What are the parameter your web page expecting

    window.open("xxxxxxxxx.html?Userid=" + retrievedUser.FullName+"&LeadID="+EntityID, "_blank");

    UserId - Is this a user id (GUID) or fullname string ??

  • Kasani Profile Picture
    Kasani 1,245 on at
    RE: Get the id of the entity.

    As I'm new to MS Dynamics CRM, so I'm confusing on  this. Can you review my code

    function Checkuser() {

       var context = Xrm.Page.context;

       var serverUrl = context.getServerUrl();

       var UserID = context.getUserId();

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

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

       var retrieveUserReq = new XMLHttpRequest();

       retrieveUserReq.open("GET", ODataPath + "/SystemUserSet(guid'" + UserID + "')", true);

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

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

       retrieveUserReq.onreadystatechange = function () {

           retrieveUserReqCallBack(this);

       };

       retrieveUserReq.send();

    }

    function retrieveUserReqCallBack(retrieveUserReq) {

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

           if (retrieveUserReq.status == 200) {

               var retrievedUser = this.parent.JSON.parse(retrieveUserReq.responseText).d;

               if (retrievedUser.FullName != null)

               window.open("xxxxxxxxx.html?Userid=" + retrievedUser.FullName+"&LeadID="+EntityID, "_blank");

           }

           else {

               alert("Error in Fetching User data");

           }

       }

    }

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Get the id of the entity.

    You need to follow these steps

    1. Get your leadid using getId only, not need to write service call for this

    2. Get User full name that you are already getting with your function

    so it should be like below

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

    var Fullname=GetUsername(); your custom function, also I am assuming you want to get current logged in user name, but you want to get current lead owner you can get it directly from lead form without writing service call

    After that you should be able to call your custom page

  • Kasani Profile Picture
    Kasani 1,245 on at
    RE: Get the id of the entity.

    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

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Get the id of the entity.

    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
    Kasani 1,245 on at
    RE: Get the id of the entity.

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

  • Kasani Profile Picture
    Kasani 1,245 on at
    RE: Get the id of the entity.

    Hi Mahender,

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

     As I don't have any custom fileld.

    Thanks,

    Kamyaka

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Get the id of the entity.

    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 ??

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans