Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Answered

Save new record in Web Resource and get its Id

Posted on by 70

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.

  • RE: Save new record in Web Resource and get its Id

    Hi Leo,

    It works, thank you very much!

    6644.Capture1.PNG

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Save new record in Web Resource and get its Id

    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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save new record in Web Resource and get its Id

    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

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans