Close MS CRM 2011 Form using JS
01 Jul 2011 7 Comments
in MS CRM 2011
Some time we need to validate based on their input values and need to close crm form if they are not validated, we can do this validation through plugin but, we can’t close form through plugin. So Javascript comes in picture here. We can do this through JS code. To close ms crm form we have close method available, we can use it like below
Xrm.Page.ui.close();
But if you will use this statement, you will get a prompt like below

to stop this prompt you need to use getSubmitMode method of attribute and need to set submitMode to never like below
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes)
{ attributes[i].setSubmitMode(“never”); }
Xrm.Page.ui.close();
Hope it will help somebody!!!



Aug 30, 2011 @ 08:25:21
Thank you so much for the script to stop the prompt.. I was struggling for this..
Thanks again ..
Regards
Chandan
Aug 30, 2011 @ 08:29:52
I am glad it helped you !!!
Oct 04, 2011 @ 06:46:42
I really mean it, thank you o lot
Oct 05, 2011 @ 13:42:07
Thanks alot for your help I used to do this in CRM 4 using window.close();
but after upgrade it stopped working, so this will be very helpful
Feb 27, 2012 @ 13:33:45
I am still getting the popup window
Feb 27, 2012 @ 15:03:12
Did you try to debug you code and checked attribute’s setsubmitmode property value ??
Apr 26, 2012 @ 06:56:14
Code was fine, but now I got another message “Are you sure, that you want navigate away from the page”