Launching a Dialog/Workflow from JavaScript

Ok folks,

this is the third and last step in overriding the default out of the box Lead qualification process. At this point we have hidden the standard Qualify button, and we have added our own Qualify button. We have pointed it to a JavaScript function to be executed. Let’s take it one step further, and actually do something in the context of CRM with all that.

It only makes sense to ask the user the standard “Are you sure?” question.

If you missed the first two articles, they are here and here.

First off, let’s go back to the solution package we’ve already created. This includes all modifications to remove the old button and add a new one. In the customizations.xml file, find the Lead entity, and the RibbonDiffXml section. Identify where we’re defining the Action to a JavaScriptFunction. We’ll add three parameters to this function, and it should look like so:

<Actions>
  <JavaScriptFunction Library="$webresource:Nav_JS_Common_Lib" FunctionName="launchWorkflow">
  <!– workflowId, entityName, entityId –>
   <StringParameter Value="{e1037cac-756c-46e7-96d0-cdc572eafc65}" />
   <StringParameter Value="lead" />
   <CrmParameter Value="FirstPrimaryItemId" />
  </JavaScriptFunction>
</Actions>

Here’s more details about the parameters.

Do note that the GUID presented is the GUID of the Dialog we’ll be launching, the “lead” is the entity it acts upon, and the FirstPrimaryItemId is the id of the Lead we’re executing against.

Now, let’s shift our attention to the JavaScript function:

function launchWorkflow(dialogID, typeName, recordId)
{
// alert("From within launchWorkflow JS function!");
 
// Load modal
  var serverUri = Mscrm.CrmUri.create(‘/cs/dialog/rundialog.aspx’);
 
  window.showModalDialog(serverUri + ‘?DialogId=’ + dialogID + ‘&EntityName=’ + typeName +
    ‘&ObjectId=’ + recordId, null, ‘width=615,height=480,resizable=1,status=1,scrollbars=1’);
 
  // Reload form
  window.location.reload(true);
}

this function is quite self explanatory, and the same format applies for any Dialog you want to call, as you define the Dialog GUID outside of the function. Thanks to Mark for making this function more streamlined than the version I came up with Winking smile I kept the same values for window size, but you can change those as needed. You might want to revisit the reload form line at the end if you are going to change the Owner of the Lead. I prefer to close the window completely after this.

With all this done, and assuming you have the Dialog completed, repackage the solution and import it. Now test it. In my case, from clicking on Qualify, I launch the first question:

image

Now from within that dialog you can put your own logic and call other Dialogs or Workflows. Sky is the limit!

Enjoy!

One thought on “Launching a Dialog/Workflow from JavaScript

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

A WordPress.com Website.

Up ↑

%d bloggers like this: