Archive
Dynamics workflow – Unable to set Email ‘Regarding’ field
Other day, while working on a straight forward ‘Send Email’ using a ‘Workflow’, I could not set the ‘Regarding’ field on ‘Email’ form.
Scenario:
- Create a new custom entity ‘Transaction’.
- Send an Email when a new ‘Transaction’ record gets created.
So, I created a new workflow on ‘Transaction’ entity and added ‘Send Email’ step.
On the ‘Email’ configuration screen, all I could see was a blank ‘Look for:’ field.
Reason & Fix:
- ‘Activities’ option was not enabled on the ‘Transaction’ entity.
- Enable ‘Activities’ and publish.
- Go to the workflow and I got the Entity Reference in ‘Look for:’ field.
Its one of those days where we struggle for trivial problems đ
âWait Conditionâ in Workflow Explained
I was asked by one of my blog followers to explain âWait Conditionâ in Workflow.
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’)
- Create an Email Activity, if âWait Conditionâ met
- Save and Activate Workflow
Test the Workflow
- Create 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
- Associate âAccountâ to the âOpportunityâ
- Check the Waiting Job now and it should have 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.
đ
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â
- Keep the Command Prompt open (i.e., Minimize it)
- Open the workflow you want debug using Visual Studio
- Attach below Processes
- Put a break point on the Workflow file
- Invoke the Workflow from console and you get the breakpoint hit on Workflow.
đ
Execute the workflow from JScript In CRM
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’>”
+ ” <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/’ “
+” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance’ “
+” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>”
+ 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) {
}
}
đ