locked
How to refresh the form when we close a dialog ? RRS feed

  • Question

  • HI,  guys how to reload a form when we click on "Finish " button from the dialog ?!!! 

    HEre is what i'm doing now... btw. we are using MS CRM 2011 Online.

    1.I have a custom button on ribbon, on click of it dialog opens

    2. Dialog will intern run a workflow and save some values in a different fields. when the form opens for the second time , button on the ribbon will be disabled if the these fields has values. which is working fine now....

    3. Once they are through with the dialog, I should be able to re-load the form so that buttons becomes disabled as soon as they come of the dialog pop-up.

    The problem we are facing is, this dialog being one time activity per lead. even after the they are done with dialog buttons will be enabled ,  user can click and bring up the pop- up again.. :(

    This is my code...

    function LESDialog() {
    
            var dialogId = "XXXXXXXXX-XXXXX-XXXXX-XXXXXXX";
            var w = 800;
            var h = 520;
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 2);
    
            var returnValue = window.open("/cs/dialog/rundialog.aspx?DialogId=%7b"
         + dialogId + "%7d&EntityName=lead&ObjectId=" + Xrm.Page.data.entity.getId(), 'null', 'width=' + w + ',height=' + h + ',toolbar=no, scrollbars=no, top=' + top + ', left=' + left + ',resizable=no, directories = no, status = no, menubar = no');
            window.focus();
    
        }

    I tried with adding this line : 

    window.location.reload(true);

    but this will reload the form as soon as the pop up opens.. i think there should be some timer or something.. there is no event to trigger on click of "Finish" button from dialog !!!

    Thursday, October 24, 2013 3:30 AM

Answers

  • Hi Pradeep,

    your reload attempt mentioned is workign as soon as pop-up opens because pop-up is not a model dialog. Can you try opening this dialog URL which you prepared in a showModelDialog() if it works that way and then refresh your ribbon in the next line. This should reload your enableRules on the custom ribbon button to disable it. Idea is control should wait till your popup is closed. In window.open it will open window & proceed to next line.   

    I have not tried to implement this myself but you can try if this helps.

    • Marked as answer by Pradeep47 Monday, October 28, 2013 5:26 AM
    Friday, October 25, 2013 6:03 AM

All replies

  • Hi,

        Instead of all of this, how about setting a value for a hidden field in the dialog and checking the value for the field to make sure it is not set before opening the dialog?

        That would work fine and you can leave the button enabled all the time.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Minal Dahiya Thursday, October 24, 2013 4:17 AM
    Thursday, October 24, 2013 4:17 AM
  • Hi,

        Instead of all of this, how about setting a value for a hidden field in the dialog and checking the value for the field to make sure it is not set before opening the dialog?

        That would work fine and you can leave the button enabled all the time.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    we can really do this ?!!! i am okay with button being enabled , and  alert message would suffice... 

    You are suggesting to  create a hidden field in in the Dialog  which will be filled at first run of the dialog, on the second run , I should be checking for the value in the that hidden field ?!! 

    I did try something similar .. not the hidden filed in the Dialog, I checked for the one of the field that dialog fills up in the first run of the dialog.. when the  user clicks on the second time on the button without closing the record, the Dialog still pops up !!! I think the value will not be reflected in the field untill we re-open a filed or refresh the page...

    Thursday, October 24, 2013 4:48 AM
  • Hi,

        I was suggesting a hidden field on the form. Apologies for not being clear there. I would suggest check if the form is dirty or not and force save the form before proceeding. This should fix the issue for you.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Thursday, October 24, 2013 4:55 AM
  • Hi,

        I was suggesting a hidden field on the form. Apologies for not being clear there. I would suggest check if the form is dirty or not and force save the form before proceeding. This should fix the issue for you.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Yes.. that make sense .. but stilln to getting where exactly to add this..

    Here is how  i am trying..

    function LESDialog() {

        var inputQuality = Xrm.Page.getAttribute('new_letminputquality').getValue();
        if (Xrm.Page.data.entity.getIsDirty()) {
        
                  alert("Lead scoring  is already given for this lead")
        }
        else
    {
       var dialogId = "EC8CD008-95F2-428A-8CE3-BE8B691512B9";
            var w = 800;
            var h = 520;
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 2);

            var returnValue = window.open("/cs/dialog/rundialog.aspx?DialogId=%7b"
         + dialogId + "%7d&EntityName=lead&ObjectId=" + Xrm.Page.data.entity.getId(), 'null', 'width=' + w + ',height=' + h + ',toolbar=no, scrollbars=no, top=' + top + ', left=' + left + ',resizable=no, directories = no, status = no, menubar = no');
            window.focus();
       Xrm.Page.data.entity.save();
        }

    }

    Thursday, October 24, 2013 5:27 AM
  • Hi,

          Try following:

    function LESDialog() {
    
    if (Xrm.Page.data.entity.getIsDirty()) {
         Xrm.Page.data.entity.save();
    }
    
         var inputQuality = Xrm.Page.getAttribute('new_letminputquality').getValue();
    
    if(inputQuality !=null && inputQuality <> desired value){
      
        var dialogId = "EC8CD008-95F2-428A-8CE3-BE8B691512B9";
             var w = 800;
             var h = 520;
             var left = (screen.width / 2) - (w / 2);
             var top = (screen.height / 2) - (h / 2);
    
             var returnValue = window.open("/cs/dialog/rundialog.aspx?DialogId=%7b"
          + dialogId + "%7d&EntityName=lead&ObjectId=" + Xrm.Page.data.entity.getId(), 'null', 'width=' + w + ',height=' + h + ',toolbar=no, scrollbars=no, top=' + top + ', left=' + left + ',resizable=no, directories = no, status = no, menubar = no');
             window.focus();
        Xrm.Page.data.entity.save();
         }
    
     

        Replace Desired value to what you are setting it to validate first.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Thursday, October 24, 2013 5:39 AM
  • Hi,

          Try following:

    function LESDialog() {
    
    if (Xrm.Page.data.entity.getIsDirty()) {
         Xrm.Page.data.entity.save();
    }
    
         var inputQuality = Xrm.Page.getAttribute('new_letminputquality').getValue();
    
    if(inputQuality !=null && inputQuality <> desired value){
      
        var dialogId = "EC8CD008-95F2-428A-8CE3-BE8B691512B9";
             var w = 800;
             var h = 520;
             var left = (screen.width / 2) - (w / 2);
             var top = (screen.height / 2) - (h / 2);
    
             var returnValue = window.open("/cs/dialog/rundialog.aspx?DialogId=%7b"
          + dialogId + "%7d&EntityName=lead&ObjectId=" + Xrm.Page.data.entity.getId(), 'null', 'width=' + w + ',height=' + h + ',toolbar=no, scrollbars=no, top=' + top + ', left=' + left + ',resizable=no, directories = no, status = no, menubar = no');
             window.focus();
        Xrm.Page.data.entity.save();
         }
    
     

        Replace Desired value to what you are setting it to validate first.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Thanks minal for the hlep, but still i am not able to fix it..

    I think the problem is the values on filed don't get update if we don't refresh the page or re load the page. because Dialog updates the value asynchronously.. so even i try to get the value on without refreshing the page it will not return updated value..  

    Thursday, October 24, 2013 6:16 AM
  • Hi,

        Agree. But think practically. Most times users will close the form after running the dialog once and something like this can be trained rather than trying to cover everything in coding.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Thursday, October 24, 2013 9:38 PM
  • we , being programmers think practically.. but users, They don't think the way we think.. :) Otherwise most of our issues  would haven be dealt easily.. 

    anyways.. i'm trying to retrieve the updated values using RESTend points from the server directly not from client side scripting.. not sure about the result.. but i am going to give it a  try anyway... 

    Friday, October 25, 2013 4:32 AM
  • Hi Pradeep,

    your reload attempt mentioned is workign as soon as pop-up opens because pop-up is not a model dialog. Can you try opening this dialog URL which you prepared in a showModelDialog() if it works that way and then refresh your ribbon in the next line. This should reload your enableRules on the custom ribbon button to disable it. Idea is control should wait till your popup is closed. In window.open it will open window & proceed to next line.   

    I have not tried to implement this myself but you can try if this helps.

    • Marked as answer by Pradeep47 Monday, October 28, 2013 5:26 AM
    Friday, October 25, 2013 6:03 AM
  • Hi Pradeep,

    your reload attempt mentioned is workign as soon as pop-up opens because pop-up is not a model dialog. Can you try opening this dialog URL which you prepared in a showModelDialog() if it works that way and then refresh your ribbon in the next line. This should reload your enableRules on the custom ribbon button to disable it. Idea is control should wait till your popup is closed. In window.open it will open window & proceed to next line.   

    I have not tried to implement this myself but you can try if this helps.

    I thought I almost solved the problem, As you suggest I tried showModelDialog(), it refreshed the main form AFTER I click on finish from the Dialog.. yet.... the button remains visible. I guess dialog-workflow needs more time to update the record :( .. it's a no go then !!! 

    Sunday, October 27, 2013 12:52 PM