Showing posts with label dialog. Show all posts
Showing posts with label dialog. Show all posts

Tuesday, October 25, 2016

Xrm.Utility functions : Dialogs

There are useful functions in Xrm.Utility object. These functions are not directly related to current page. 

Dialogs:
In older version of CRM, if you want to show alert or confirm dialog, then we have to JavaScript alerts / confirm dialog, but now there are two functions in Xrm.Utility which will give same functionality. 

When we want to show alert message on form or button click we can Xrm.Utility object. 

alertDialog
alertDialog we can use to show just message or when dialog closed, we can call any javascript function. 

Xrm.Utility.alertDialog(message,onCloseCallback)

Example:

contactScript =
{
    NoTaskCreated: function () {
        Xrm.Utility.alertDialog("No Task created.", contactScript.TaskDialogClose);
    },
    TaskDialogClose: function () {
        Xrm.Utility.alertDialog("Dialog Closed");
    },
};

Here in above example, in NoTaskCreated  function calling alertDialog with callback function(contactScript.TaskDialogClose) which will be called when user closes this alert dialog. And TaskDialogClose function shows alertDialog without callback function. 

confirmDialog
confirmDialog will show OK and Cancel buttons with message, and you can call functions when user clicks on OK and Cancel buttons.
Xrm.Utility.confirmDialog(message,yesCloseCallback,noCloseCallback)

Example:
contactScript =
{
    OnSaveContact: function () {
        Xrm.Utility.confirmDialog("Do you want to Create Followup Task?",
contactScript.CreateTask, contactScript.NoTaskCreated);
},
    NoTaskCreated: function () {
        Xrm.Utility.alertDialog("No Task created.", contactScript.TaskDialogClose);
    },
    TaskDialogClose: function () {
        Xrm.Utility.alertDialog("Dialog Closed");
    },
    TaskCreated: function () {
        Xrm.Utility.alertDialog("Task Created.");
    },
};

In this above example, when contact record is saved calling OnSaveContact function, which will ask user about creating follow-up task. This message will be shown using confirmDialog and based on user’s action either TaskCreated function will be called or TaskDialogClose function is called.

Wednesday, May 6, 2015

Running CRM Dialog from Custom Ribbon button


 1.      Add custom button on form
Say Run Dialog


     2. Now create command for custom button

     3. Add  Action to command

For the action add “Open Url Action”



3. For Url Command set your dialog URL
         To get dialog URL run dialog using “Start Dialog” button


Then select dialog you want to run on button click, once dialog started copy URL of dialog from address bar



 5. Your dialog url will be look like 

https://{CRM Server}:444/cs/dialog/rundialog.aspx?DialogId=%7b83D90936-EBEC-4CE5-8A58-A1530DE30680%7d&EntityName=new_test&ObjectId=%7b0FCB7F66-5FA6-E411-B1DF-0050568C6D7D%7d

It has Dialogid, Entityname and ObjectId
ObjectId is the record id on which this Dialog is running.

 6. If you use this URL as it is on button command then dialog will be run on same record again and again. 

      7.  To pass ObjectId / record id dynamically, need to pass one parameter to Url command, defined for custom button. This parameter should be like




    8. Now update your URL command address to

https://{CRM Server}:444/cs/dialog/rundialog.aspx?DialogId=%7b83D90936-EBEC-4CE5-8A58-A1530DE30680%7d&EntityName=new_test

Noticed that I removed &ObjectId=%7b0FCB7F66-5FA6-E411-B1DF-0050568C6D7D%7d, this objectId is passed by parameter, that’s why Parameter Name is important. 

    9.  Save and publish your customization.


   10.   Now dialog will be run for record you are in from button.