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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

Save new record in Web Resource and get its Id

(0) ShareShare
ReportReport
Posted on by 76

Hello,

When I click New button and create a new record, opens a new form(Client), In that form I have web resource (type=HTML), in this web resource I need to save this record and get Id.

How can i do this ? I try to write 

window.parent.Xrm.Page.data.save();
window.parent.Xrm.Page.data.refresh();

var entityId = window.parent.Xrm.Page.data.entity.getId();

but var entityId = ""

How can I get Id ? 

Thanks.

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Marina,

    Try to get the id in the onsave event of the form. Create a new function onSave and attach it to the onsave handler of the form. At that point the record id should be ready to consume.

    Thanks

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner, 

    You could try my code here.

    <script>
            function myFunction() {
                window.parent.Xrm.Page.data.save().then(successCallbackerrorCallback);
                
            }
            function successCallback(){
                var entityId = window.parent.Xrm.Page.data.entity.getId();
            }
            function errorCallback(){
                alert("error")
            }
        </script>

    3343.pastedimage1570159361592v1.png

    The reason why you did not catch the recordid is that when you save&refresh the form, the "window.parent.Xrm.Page.data.entity.getId();" function could not get the latest data.

    So I add a callback function in "save" action and when the system saved the record successfully, it will return the correct record id.

    Hope it helps.

    Best Regards,

    Leo

  • Marina Karapetyan Profile Picture
    76 on at

    Hi Leo,

    It works, thank you very much!

    6644.Capture1.PNG

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
KristineRisberg Profile Picture

KristineRisberg 37

#2
11manish Profile Picture

11manish 35

#3
Manoj - ManoVerse Profile Picture

Manoj - ManoVerse 21 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans