Sample: Work with business process flows
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises)
This sample demonstrates how to programmatically work with business process flows such as retrieving the business process flow instances for an entity record, retrieving active path for a business process flow instance and its process stages, and changing the active stage. For information about these concepts, see Model business process flows
This sample is for December 2016 update for Dynamics 365 (online and on-premises), and is available to download from Sample: Work with business process flows.
In This Topic
Prerequisites
What this sample does
Run the sample
Prerequisites
Before you can run the sample:
Have access to a December 2016 update for Dynamics 365 (online and on-premises) organization.
Have appropriate privileges on the Lead, Opportunity, and Workflow entities and business process flow definition entity records used in this sample.
Visual Studio 2013, Microsoft Visual Studio 2015 or later to run the sample.
Have Internet connection to download the sample project and to restore the NuGet packages used in the sample project.
What this sample does
Creates a sample Lead record. This automatically creates an instance of the "Lead To Opportunity Sales Process" business process flow for the Lead record.
Converts the Lead record to an Opportunity record.
Retrieves the business process flow instances associated with the "Opportunity" record using the RetrieveProcessInstances message. The first record in the returned collection is the active business process flow instance for the opportunity record, which is "Lead To Opportunity Sales Process" in this case.
Retrieves the active path and the process stages for the "Lead To Opportunity Sales Process" instance using the RetrieveActivePath message.
Retrieves the currently active stage for the "Lead To Opportunity Sales Process" instance, and prompts the user whether to move to the next stage. On confirmation to move, sets the next stage in the active path as the active stage for the "Lead To Opportunity Sales Process" instance.
Finally, prompts the user whether to delete the records created during the sample run.
Here is the output of the sample:
Run the sample
Download the WorkWithBPFVisual Studio sample project, and extract it to a folder on your computer.
Locate the WorkWithBPF.sln file in your extracted folder, and open it in Visual Studio.
The sample project uses NuGet packages that must be restored before running the sample. Ensure that automatic restore of NuGet packages is enabled in Visual Studio. More information: Enabling and disabling NuGet package restore
Alternatively, select Project > Manage NuGet Packages, and select Restore to manually restore the packages used in the sample.
Press F5 or select Debug > Start Debugging.
If you have not previously run one of the Microsoft Dynamics 365 managed code samples before, you’ll need to enter information to run the code, otherwise enter the number for one of the Dynamics 365 servers you have previously set up.
Prompt
Description
Enter a Dynamics 365 server name and port [crm.dynamics.com]
Type the name of your Microsoft Dynamics 365 server. The default is Microsoft Dynamics 365 (online) (crm.dynamics.com) in North America.
Example:
crm5.dynamics.comIs this organization provisioned in Microsoft online services (y/n) [n]
Type y if this is a Microsoft online services provisioned organization. Otherwise, type n.
Enter domain\username
Type your Microsoft account.
Enter password
Type your password. The characters will show as “*” in the window. Your password is securely saved in the Microsoft Credential Manager for later reuse.
Specify an organization number (1-n) [1]
From the list of organizations shown that you belong to, type the corresponding number. The default is 1, indicating the first organization in the list.
The sample will perform the operations described in What this sample does and may prompt you with additional options
When the sample is complete, press ENTER to close the console window.
See Also
Microsoft Dynamics 365
© 2017 Microsoft. All rights reserved. Copyright2