The views and opinions expressed in this blog are those solely of the author(s) and do not necessarily reflect Microsoft’s current policy, position, or branding. For official announcements and guidance on Dynamics 365 apps and services, please visit the Microsoft Dynamics 365 Blog.
Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 release wave 1Discover the latest updates and new features to Dynamics 365 planned through September 2020
Release overview guides and videos Release Plan | Preview 2020 Release Wave 1 TimelineWatch the 2020 Release Wave 1 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
For the latest updates to this post please visit the original posting here: How to Execute a Failed Workflow Using CRM ExecuteWorkflowRequest in a Console Application
Workflows are an extremely useful tool in Microsoft Dynamics CRM. In today’s blog, we’ll discuss how to execute a workflow using the CRM ExecuteWorkflowRequest message in a console application.
In this scenario, a workflow has failed a couple of times. Instead of re-running this workflow manually, we can use the code below to automate the process.
The screenshot below shows the System Jobs view of the workflow named Workflow Test that has failed.
The ExecuteWorkflowRequest message can be used to execute any given workflow. The ExecuteWorkflowMessage requires two values:
Note: You must ensure that the WorkflowId is of an active workflow.
You can manually set these values by using the CRM interface to attain each of these values and simply call the ExecuteWorkflowRequest in the console application.
The following code automates this process by doing the following:
Console application code
After the console application executed, the failed workflow was rerun.
System Jobs view after console application was executed and workflow succeeded
When a workflow is created, CRM creates two entries in the workflow entity. When retrieving failed workflows from the asyncoperation entity, you will notice the workflowactivationid attribute has a reference to the workflow. If you attempt to use this value as the WorkflowId, you will get an error stating “Workflow must be in a published state” when the ExecuteWorkflowRequest message is executed.
The GetWorkflowId helper method is used to retrieve the published workflow by querying the workflow entity and retrieving the parentworkflowid attribute. This value will correspond to the WorkflowId that you will get when using the CRM interface.
You will want to expand the logic to determine a distinct set of failed workflows and regarding entity that have not succeeded.
There you have it! An easy way to automatically execute a workflow using a console application. If you are looking for help with your workflows, PowerObjects can help! Contact us for more information.
The post How to Execute a Failed Workflow Using CRM ExecuteWorkflowRequest in a Console Application appeared first on PowerObjects.
Business Applications communities