Advertisements

Archive

Posts Tagged ‘Workflow’

‘Wait Condition’ in Workflow Explained

February 19, 2017 1 comment

I was asked by one of my blog followers to explain ‘Wait Condition’ in Workflow.

wait-condition

To explain this better, I took a small scenario

  • Send an Email to Opportunity Owner, whenever an Account has been assigned to the Opportunity

Configuring Work Flow :

  • Create a workflow on Opportunity which triggers when ‘Record is created’
  • Add a “Wait Condition” to check, if Account got assigned to Opportunity (I.e., Opportunity. Account ‘Contains Data’)

workflow-wait-condition

  • Create an Email Activity, if ‘Wait Condition’ met

workflow-send-email-when-wait-condition-met

  • Save and Activate Workflow

Test the Workflow

  • Create new Opportunity

new-opportunity

  • Check the Waiting job in ‘System Jobs’
    • Since we have the Wait condition set in our workflow, the Job will wait until the condition met

waiting-job

  • Associate ‘Account’ to the ‘Opportunity’

opportunity-associated-account

  • Check the Waiting Job now and it should have completed.

waiting-job-completed

  • New Email created in system as the follow up action

Key Points to consider before using Wait Conditions:

While the ‘Wait conditions’ are useful in case of the timer related tasks which will be achieved with no coding, excessive use of wait conditions has a downside.

  • Performance:
    • Each waiting workflow instance carries performance overhead. The more waiting workflow you have, the more server resources will be consumed by the Asynchronous Processing Service.
    • If you change the logic in your workflow and republish (like update the text of the email sent to your client), it does not change waiting workflow instances. For example, if you change the renewal email frequency to 15 days rather than 30 days, any workflow instances that are waiting will not be updated.

🙂

 

Advertisements
Categories: CRM Tags: ,

How to debug XAML Workflows when invoked remotely

Assume you have a XAML workflow created using WF designer and you trigger this workflow from a console application which is in another server.

Below are the steps to debug

  • Install “Workflow Manager Tools”
  • After installation you can find a folder under “C:\Program Files (x86)\Workflow Manager Tools\1.0”
  • Open “Microsoft.Workflow.TestServiceHost.exe.config” using Visual Studio
  • Make sure all ‘connectionStrings’ pointing to proper Data base.
  • Open “Command Prompt” as Administrator.
  • Point to “C:\Program Files (x86)\Workflow Manager Tools\1.0”, Run the “Microsoft.Workflow.TestServiceHost.exe”
WF Test Service Host

WF Test Service Host

  • Keep the Command Prompt open (i.e., Minimize it)
  • Open the workflow you want debug using Visual Studio
  • Attach below Processes
Attach Processes

Attach Processes

  • Put a break point on the Workflow file
Break Point on WF file

Break Point on WF file

  • Invoke the Workflow from console and you get the breakpoint hit on Workflow.

🙂

Categories: Misc Tags: , ,

Execute the workflow from JScript In CRM

October 2, 2011 1 comment

Hi,

We can run the CRM workflows from JScript, if we know the GUID of the workflow. Below are the execution steps.

Steps :-

  • Get the GUID of workflow from name using OData Service  (i.e., Using GetWorkflowIDByName(wfName) function )
  • Execute the Workflow using the GUID (i.e., Using TriggerWorkflow(workflowGuid) function)

Below are the JScript functions mentioned in above steps.

function GetWorkflowIDByName(wfName) {

var serverUrl = Xrm.Page.context.getServerUrl();

//Prepare ODATA query to fetch WF GUID by WF Name

var odataSelect = serverUrl + “/xrmservices/2011/OrganizationData.svc/WorkflowSet?$select=WorkflowId&$filter=ActiveWorkflowId/Id ne null and Name eq ‘” + wfName + “‘”;

$.ajax({

type:“GET”,

contentType:“application/json; charset=utf-8”,

datatype:“json”,

url: odataSelect,

beforeSend:function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader(“Accept”, “application/json”); },

success:function(data, textStatus, XmlHttpRequest) {

RetrieveWorkflow(data.d);

},

error:function (XmlHttpRequest, textStatus, errorThrown) { alert(‘OData Select Failed: ‘+ odataSelect); }

});

}

function RetrieveWorkflow(Entity) {

var objFilteredWF = null;

objFilteredWF = Entity;

wfID =null;

//Get the WF GUID from OData result set

if (objFilteredWF != null && objFilteredWF.results != null && objFilteredWF.results.length != 0 && objFilteredWF.results[0].WorkflowId != null) {

wfID = objFilteredWF.results[0].WorkflowId;

TriggerWorkflow(wfID);

}

}

//Trigger WF using WorkflowGUID

function TriggerWorkflow(workflowGuid) {

try{

var soapBody = “<soap:Body>”+” <Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>&#8221;

+ ” <Request xsi:type=\’ExecuteWorkflowRequest\’>”

+” <EntityId>” + Xrm.Page.data.entity.getId() + “</EntityId>”

+” <WorkflowId>” + workflowGuid + “</WorkflowId>”

+” </Request>”

+” </Execute>”

+“</soap:Body>”;

/*Wrap the Soap Body in a soap:Envelope.*/

var soapXml = “<soap:Envelope “

+” xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/&#8217; “

+” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance&#8217; “

+” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>&#8221;

+ GenerateAuthenticationHeader()

+soapBody +

“</soap:Envelope>”;

/* Create the XMLHTTP object for the execute method.*/

var xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);

xmlhttp.open(“POST”, “/MSCRMservices/2007/crmservice.asmx”, false);

xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

xmlhttp.setRequestHeader(“SOAPAction”, http://schemas.microsoft.com/crm/2007/WebServices/Execute);

/* Send the XMLHTTP object. */

xmlhttp.send(soapXml);

}

catch(e) {

}

}

🙂