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)

Finding new entity id after Save

(0) ShareShare
ReportReport
Posted on by

I have an iFrame with a custom web page loaded.  The page (on_load) looks for the entity id (this is a custom entity).  When the record exists, this works fine, however, when I create a new record there is no ID initially so it displays an error.  All that is as expected.

I am trying to refresh the link when the record is saved.  I have created a javascript function that reads the current link.src, attempts to append the new record id, and then puts the new url as the new .src for the link.

So this runs in the onSave event for this form:

//lnk is passed in as the control name for this iFrame and it is valid and working

var formType = Xrm.Page.ui.getFormType();

var src = Xrm.Page.getControl(lnk).getSrc();

if (formType == 1) {

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

 if (rmaid == null || rmaid == "") { setTimeout("doRefreshLink()", 1000); }

else {

src += rmaid;

document.getElementById(lnk).src = src;

}

}

It appears the server side save will not run until this onSave function is completed (not running asynchronously).  Is that true?

The real issue is how to I get the ID so I can refresh this page?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    Hi Don,

    If you need to do something to the entity just before it's being saved (or maybe after the save but before postback to the client) you might want to intercept the operation using a plugin

    Refer this link:

    stackoverflow.com/.../getting-a-records-guid-before-save-operation

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Rajkumar Rajaraman Profile Picture
    on at

    Refer this link also:

    stackoverflow.com/.../how-to-get-id-of-saved-enitity

    Regards,

    R.Rajkumar

  • Royal King Profile Picture
    27,686 on at

    you could add function on the onSave of the record and update the url of the Iframe to refresh with the new record id.

  • Suggested answer
    Community Member Profile Picture
    on at

    I wouldn't do it via JavaScript unless your pretty keen on the transactions and threads from the client side from XRM.

    Do a simple plugin that gets called on Post Entity Create to grab the GUID.

    Here is a great video if you are not familiar how to do this:

    www.youtube.com/watch

  • Verified answer
    Community Member Profile Picture
    on at

    Hi all,

    Thanks for your help, but the answer was in my placement.  I moved the code the onLoad event and reversed my condition (NOT a new form) AND determined if the id was part of the url passed to my iFrame.  If the ID was not present, I get it from the entity and append it to the src url.  Here is the final code:

    function doRefreshLink(lnk){

       var formType = Xrm.Page.ui.getFormType();

       var src = Xrm.Page.getControl(lnk).getSrc();

       if (formType != 1) {

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

           var pos = src.indexOf("&id=");

           var curid = src.substring(pos + 4);

           if (curid == ""){

               src += rmaid;

               document.getElementById(lnk).src = src;

           }

       }

    }

    Fortunately, the id parameter was at the end of the line or it would have been a bit more parsing.

    Thanks for your help though - this forum has been instrumental in my completing many of these tasks.

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