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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How can i retrieve current record guid in java script.

(0) ShareShare
ReportReport
Posted on by

Hello,

I'm  saveing my entity record using Xrm.Page.data.entity.save(); using javascript.
next line I want to retrive my current save record guid using 

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

It is giving me null value.

Please help me

How can i retrieve current record guid in java script.

Thanks 
Kashyap Diwan

*This post is locked for comments

I have the same question (0)
  • P. R. M Profile Picture
    739 on at
    RE: How can i retrieve current record guid in java script.

    I have tried below method as suggested by Andrew Butenko. Its working for me....Thanks.

    Xrm.Page.data.save().then(function () {

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

                                       //Send Email

                                       email.SendEmail(id);                                  

                                       Xrm.Page.data.refresh();

                                   }, function () {

                                       //handle error here

                                   });

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: How can i retrieve current record guid in java script.

    Hi Kashyap,

    See: community.dynamics.com/.../177919

    Hope this helps.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How can i retrieve current record guid in java script.

    Hello,

    Try to use something like following:

    Xrm.Page.data.save().then(function(){

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

    }, function(){

    //handle error here

    });

  • Verified answer
    Luke Sartain Profile Picture
    1,266 on at
    RE: How can i retrieve current record guid in java script.

    Before going down the plugin route try incorporating a callback function.  Not had time to test that it works myself but something like:

    var callBackSuccess = function(){

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

    }

    var errorCallback = function(error){

         console.log(error.message);

    }

    Xrm.Page.data.entity.save().then(callBackSuccess, errorCallback);

    Alternatively you can try refreshing the form data after the save before retrieving the Id.

    Edit:  Here's the MSDN link. https://msdn.microsoft.com/en-us/library/dn481607(v=crm.6).aspx

  • Suggested answer
    Kishor Kumar Profile Picture
    3,710 on at
    RE: How can i retrieve current record guid in java script.

    Once Record is Saved only, then only it  will create a new Guid and then you can retrieve.

    If you want retrieve the record after the Database transaction, as suggested by Alagu use the images in the plugin and you can get the data

    Check this

    crmbook.powerobjects.com/.../plug-in-images-pre-vs-post

    In Plugin too, once its saved you get the GUID using the Post Images in the plugin.

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at
    RE: How can i retrieve current record guid in java script.

    At the time of new record Xrm.Page.data.entity.getId() because record is not yet save. If you want you go ahead plugin post operation and do your logic.

  • Suggested answer
    Rahul G J Profile Picture
    605 on at
    RE: How can i retrieve current record guid in java script.

    Hi Kashyap,

    Unless the data is saved in DB, the system would not generate GUID for the record, it will be null.

    Follow this, this might help  you: 

    https://community.dynamics.com/crm/f/117/t/134587

    Hope this solves the problem.

    Regards,

    Rahul 

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans