web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Working with Business Process Flows

Community Member Profile Picture Community Member

Working with Business Process Flow is an important and itegral part of Dynamics CRM. There are situations when as a developer you come across situations where you wish to abort the BPFs or switch to a new BPF process or change the stage.

Entities and BPF:

When we create a BPF, we create entities associated to it. If we create a BPF as ‘Test Process Flow’, then a new entity is created as ‘new_bpf_xxxxxxxxxxxxxxxxxxxxxx’. Where xxxxxxx represents a Guid.

While creating a BPF we also mention other entities associated to it. So if we have associated Opportunity with BPF then a field will be present in BPF as ‘bpf_opportunityid’ along with other fields. I have mentioned this field specifically because we will be using it in our further discussion.

 

Aborting a Process:

There are 2 steps required to abort a process.

Identify the process to abort:

You may want to learn about how to connect to CRM before proceeding further.

Since you are aware of name of BPF to abort and name of entity as mentioned above, so you need to create a query to fetch the “businessprocessflowinstanceid” (guid of entity) based on the opportunity (since we are working on opportunity).

BPF1

Abort the process:

Now you have to update the statecode and statuscode to abort this process. To update the entity you can use the UpdateRequest method.

BPF2

On successful execution of this request, your BPF will be aborted with appropriate statecode and statuscode. Don’t forget to note the value of statecode and statuscode.

 

Switching BPF to a new process:

Switching to a new BPF is also a 2 step process.

Identify the new process:

While we used the entity related to BPF when we needed to abort the process, we will use the workflow entity while switching to a new process. Workflow entity contains the details regarding BPFs. Here we will query the guid of workflow entity related to new BPF process.

BPF3

Switching to new process:

Now you have the new process id, to switch the process we can use SetProcessRequest Class. This will update the opportunity with new process id which we fetched in last step.

BPF4

On successful execution of this request, your BPF will be switched to new BPF.

 

Changing the stage of BPF:

Processstage entity in CRM contains information regarding a process and its associated stages. Also opportunity entity contains “processid” and “stageid” fields.

To move to a new stage you will be having a stage name and follow below steps:

  • Query the opportunity entity to fetch the processid.
  • Query the processstage entity by passing processid and stage name to fetch the stageid.
  • Update the opportunity with new stageid.

BPF5

On successful execution of this request, your BPF will move to new stage.

Important note: 

While trying to move to a new stage, if your opportunity has some required fields which needs to be populated and these fields don’t have any value then this execution will throw exception with proper details. So please make sure that you have populated all required fields before moving to new stage.



This was originally posted here.

Comments

*This post is locked for comments