Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How can i retrieve current record guid in java script.

Posted on by Microsoft Employee

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

  • P. R. M Profile Picture
    P. R. M 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
    Nithya Gopinath 17,074 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
    a33ik 84,323 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
    Luke Sartain 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
    Kishor Kumar 3,702 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
    Alagunellaikumar 6,210 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
    Rahul G J 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans