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)

Alert user and prevent save when a value changed by plugin

(0) ShareShare
ReportReport
Posted on by

We have a scenario where a pre validation plugin check to see if there are any records with a particular values already in the entity. If there is then a two option set field called new_showerror is updated from No, the default, to Yes.

We have a JavaScript function that is called if the value of new_showerror becomes Yes. The function sends an alert to the screen and prevents the execution of the save.

To stop the execution I have to use the JavaScript on the Save call, but alert does not appear and the save is not prevented because by the time the new_showerror field has been change the page is past the point at which the JavaScript gets called. In short, the field is updated but we never see the alert and we never stop the execuction.

 

If I put the JavaScript on the new_showerror onChange event I get the error but then I am unable to get the context to prevent the save.

Is there a way of preventing  a save from the field change event? Or is there another way of going about this completely?


Thanks for your time.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi!

    The save validation needs happens client side before the plugin fires, otherwise the only way to prevent the save is to throw an exception in the plugin (which will look ugly to the user if autosave is turned on).

    You'll want to do validation in the save event in JS, then prevent the save using preventDefault (here's the documentation on that msdn.microsoft.com/.../gg509060(v=crm.6).aspx )

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

  • Suggested answer
    Community Member Profile Picture
    on at

    Could you not put your plugin code into a Custom Workflow assembly, create an action in the UI which runs the CWA and then call the action in jscript on save? If the response back is true then use your prevent save?

    Let me know if you need anymore info

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