CRM2011-How to close Dialog-"Unsaved Changes"(Not the parent Window) from a Javascript
-
Wednesday, May 02, 2012 5:30 AM
CRM2011-How to close Dialog-"Unsaved Changes"(Not the parent Window) from a Javascript
I am using below Javascript to close the Dialog-"unsaved Changes" but it is now working.
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes)
{ attributes[i].setSubmitMode("never"); }Am i missing something?? If i use Xrm.Page.ui.close(); under the above lines it is closing the parent window as well.
Any response on this would be much appreciated.
Madhu M.
All Replies
-
Wednesday, May 02, 2012 5:34 AMModerator
How and where are you writing this code, do you have two open forms ??
Mahain : Check My Blog
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question. -
Wednesday, May 02, 2012 5:42 AM
We are using Multiforms. I have Javascript to change form based on the Picklist values, while changing from one form to other Dialog is shown.
I am looking for some JS to close the dialog to display the other form.
Madhu M.
-
Wednesday, May 02, 2012 5:52 AMModerator
where are you writing this code - have you written this on both forms or on single form, what is the sequence of code share it here.
Mahain : Check My Blog
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question. -
Wednesday, May 02, 2012 5:58 AM
Both the forms, calling ONLOAD
var programlookup = new Array();
programlookup = Xrm.Page.getAttribute("msft_programid").getValue();
if (programlookup != null)
{
var name = programlookup[0].name;
var guid = programlookup[0].id;
var entType = programlookup[0].entityType;
// alert(Xrm.Page.ui.formSelector.getCurrentItem().getLabel());
if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != name)
{
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items)
{
var item = items[i];
var itemId = item.getId();
var itemLabel = item.getLabel()
if (itemLabel == name)
{
item.navigate();
var attributes = Xrm.Page.data.entity.attributes.get();
for (var j in attributes)
attributes[j].setSubmitMode("never");
}
//Xrm.Page.ui.close();
}
}
}
Madhu M.
- Edited by Madhu_M Wednesday, May 02, 2012 6:05 AM added JS
-
Wednesday, May 02, 2012 6:11 AMAnswerer
Hi Madhu,
As I said on your previous post, I dont think that this is the right approach. Role based forms are not designed to change the form layout when you change a value on the form, they are designed to give people in your organisation a layout that is specific to their role. The dialog that you are trying to close is shown because you have unsaved changes and you need to save the record or they will be lost when the form refreshes. A better method is to use JavaScript to show/hide fields, sections and tabs when you change your optionset.
Hth,
Scott
Scott Durow
Read my blog: www.develop1.net/public
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful" -
Wednesday, May 02, 2012 6:14 AM
The Optionset field is readonly, we will get the values of optionset from different source.
I am looking for a JS to force Save and close the dialog or discard the changes and close the dialog.
Madhu M.
-
Wednesday, May 02, 2012 6:19 AMModerator
Is it your complete code ??
try to change sequence
var attributes = Xrm.Page.data.entity.attributes.get();
for (var j in attributes)
attributes[j].setSubmitMode("never");item.navigate();
Mahain : Check My Blog
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question. -
Wednesday, May 02, 2012 6:31 AMStill behavior is same, if i click on OK button going to Infiniteloop or if i click on Cancel... dialog is shown twice.
Madhu M.
-
Wednesday, May 02, 2012 8:33 AM
Hi,
Please share your entire onload event code.
-
Wednesday, May 02, 2012 9:04 AM
Hello Madhu_M
From your problem explanation, I concluded that you do not want the "Save Confirmation" popup while redirecting
To achieve this, right before the redirection of the form, you have do the following:
crmForm.isDirty = false;
crmForm.detachCloseAlert(); Xrm.Page.ui.close();
It will work for sure....
Enjoy....:)
Saurabh Gupta, MS CRM 2011 Software Development Engineer
-
Wednesday, May 02, 2012 12:04 PMI have share the complete JS that we are using on load. No other JS we are Using on both the forms
Madhu M.
-
Wednesday, May 02, 2012 12:17 PM
Hi,
If you are not using other code in Onload event then why you are getting this unsaved changes dialog ? It means some field/fields gets changed on form.
"The Optionset field is readonly, we will get the values of optionset from different source"- how/where you are setting OptionSet value ?
-
Wednesday, May 02, 2012 11:00 PM
Hi Saurabh,
It is closing the Parent Windows not the Dialog.
Madhu M.
-
Wednesday, May 02, 2012 11:02 PMI have removed all OnLoad JS.
Madhu M.