Firing a dialogue from an event


In Microsoft Dynamics V4 it was possible to fire a workflow from an event or isv button and with the arrival of dialogues, I thought it would be neat to be able to trigger dialogues from an event (either onload, onsave or onchange of a tab or field).


Here’s how it’s done in Microsoft Dynamics CRM2011.


The following example fires a dialogue when a record is modified. This could easily be modified to fire in different form scenarios or on evaluating a particular field using the ‘if’ condition.


Create a web resource of type JScript and add the following code:


function FireDialogue()



    
    var CRM_FORM_TYPE_CREATE = 1; 
    var CRM_FORM_TYPE_UPDATE = 2; 
    var sUrl = "";


    var crmFromType = Xrm.Page.ui.getFormType();




    if(crmFromType == CRM_FORM_TYPE_UPDATE) 
    { 
        var _return = window.confirm(Please complete the following questions..');




        if(_return) 
        { 
            sUrl = /cs/dialog/rundialog.aspx?DialogId={0B1ED4C5-9D45-4891-A7C4-3BC8652D5EFC}&EntityName=account&ObjectId=">http://<insert your crm url here>/cs/dialog/rundialog.aspx?DialogId={0B1ED4C5-9D45-4891-A7C4-3BC8652D5EFC}&EntityName=account&ObjectId= + Xrm.Page.data.entity.getId();


            window.open(sUrl, "mywindow","location=0,resizable=1,status=1,scrollbars=1, width=800,height=600"); 
        } 
    }


    return true; 
}


You will need to replace the {GUID} with the GUID of the specific dialogue that you wish to fire.


Add your JScript web resource to the form and then attach the function FireDialogue to your required event, in this case the onload event is being used so the message and dialogue fire as soon as the user opens an existing record.


This piece of script will be quite useful when there is a requirement for the users to follow a prescribed process and removes the reliance on the user pressing the ‘run dialogue’ button.