CRM2011-How to close Dialog-"Unsaved Changes"(Not the parent Window) from a Javascript

คำถาม CRM2011-How to close Dialog-"Unsaved Changes"(Not the parent Window) from a Javascript

  • 2 พฤษภาคม 2555 5:30
     
     

    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.

ตอบทั้งหมด

  • 2 พฤษภาคม 2555 5:34
    ผู้ดูแล
     
     

    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.

  • 2 พฤษภาคม 2555 5:42
     
     

    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.

  • 2 พฤษภาคม 2555 5:52
    ผู้ดูแล
     
     

     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.

  • 2 พฤษภาคม 2555 5:58
     
     

    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.


    • แก้ไขโดย Madhu_M 2 พฤษภาคม 2555 6:05 added JS
    •  
  • 2 พฤษภาคม 2555 6:11
    ผู้ตอบ
     
     

    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"

  • 2 พฤษภาคม 2555 6:14
     
     

    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.

  • 2 พฤษภาคม 2555 6:19
    ผู้ดูแล
     
     

    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.

  • 2 พฤษภาคม 2555 6:31
     
     
    Still behavior is same, if i click on OK button going to Infiniteloop or if i click on Cancel... dialog is shown twice.

    Madhu M.

  • 2 พฤษภาคม 2555 8:33
     
     

    Hi,

    Please share your entire onload event code.

  • 2 พฤษภาคม 2555 9:04
     
      มีโค้ด

    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

  • 2 พฤษภาคม 2555 12:04
     
     
    I have share the complete JS that we are using on load. No other JS we are Using on both the forms

    Madhu M.

  • 2 พฤษภาคม 2555 12:17
     
     

    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 ?

  • 2 พฤษภาคม 2555 23:00
     
     

    Hi Saurabh,

    It is closing the Parent Windows not the Dialog.


    Madhu M.

  • 2 พฤษภาคม 2555 23:02
     
     
    I have removed all OnLoad JS.

    Madhu M.