Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Delay Close of Record with JS?

Posted on by

I have some custom javascript that executes on change of the "Created On" field on a record. Everything works correctly if a user fills out all necessary fields and then clicks "Save". When a user clicks "Save and Close", however, the javascript fails to execute. I know that I can prevent the default behavior of that save and close button, but that isn't great for user experience. Is there a way to delay the close event so that the javascript can properly execute? Or does anyone know an alternate solution to an issue like this? Thanks in advance for any help.

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Delay Close of Record with JS?

    Ah.. I see. You probably can't do it, though. The way I understand it is:

    "Save button" logic:

    - Save

    - OnLoad (once the form is reloaded)

    - CreatedOn is set and your event fires

    "Save and close" logic:

    There is no reload (since the form is closed instead), so nothing happens that makes your script fire

    The code you have there may have to be moved to a plugin/workflow instead (if they run in "post-create", they will have access to the id of the record)

  • fishyjj Profile Picture
    fishyjj on at
    RE: Delay Close of Record with JS?

    Hi -- reason I am not doing that is because I need to use the guid of the record I am creating in my javascript code.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Delay Close of Record with JS?

    Hi,

      just out of curiosity.. did you try form "onsave" event instead? If you only wanted that script to work for new records, you could use getFormType method to see if it's a "create":

    https://msdn.microsoft.com/en-us/library/gg327828.aspx#BKMK_getFormType

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans