Business Process Flows data model in Dynamics 365 Online

Question Status

Verified
Mohamed Mostafa asked a question on 20 Jun 2017 5:31 AM

In the latest Dynamics 365 release (version 8.2), Business Process Flow data model has changed and now each BPF is created as a separate entity. Does anyone know where does the mapping between Stages and Steps of Business Process Flows are stored in the backend data model (i.e. which DB table)?

Reply
David Jennaway responded on 20 Jun 2017 6:49 AM

A Business Process Flow is a type of process, so is stored in the workflow entity (and workflowbase SQL table). The stages and steps are all defined in the Xaml definition in the xaml column, which is an XML document

Reply
Suggested Answer
Mohamed Mostafa responded on 20 Jun 2017 8:24 AM

Thanks David. Just to confirm, you are saying that the Business Process Flow design including stages and steps are still stored in XAML definition under the Workflow entity XAML column.

I would also add that I found out that new data model means that every instance of each Business process flow is stored as a record under the Business Process Flow own entity.

Anyone has any more information to add to this?

Reply
Verified Answer
Alex Shlega responded on 20 Jun 2017 8:54 AM

Hi Mohammed,

 Not sure about the DB table.. There is processstage entity. You can try this kind of webapi request to see what's in there:

https://<URL>/api/data/v8.2/processstages

 It'll give you all the process stages and steps per stage, it seems.

 Every process flow entity, in turn, will have a lookup to the process stage.

Reply
Verified Answer
Mohamed Mostafa responded on 21 Jun 2017 2:47 AM

Many thanks Alex. This is really helpful. I think this might be the entity I was looking for.

Here is what I found:

Process Stages Entity contains: Step metadata for process stage (Client Data). It also contains stage Category (Qualify, Develop, Propose, etc.) and also Stage Name.

Here is a table of the Entity Properties for SDK calls:

Name

Type

Details

clientdata

Edm.String

Description: Step metadata for process stage

Display Name: Client Data

Read-only property

owningbusinessunit

Edm.Guid

Description: Select the business unit that owns the record.

Display Name: Owning Business Unit

Read-only property

primaryentitytypecode

Edm.String

Description: Primary entity associated with the stage.

Display Name: Primary Entity

processstageid

Edm.Guid

Description: Shows the ID of the process stage record.

Display Name: Process Stage

stagecategory

Edm.Int32

Description: Select the category of the sales process.

Default Options:

0 : Qualify
1 : Develop
2 : Propose
3 : Close
4 : Identify
5 : Research
6 : Resolve
7 : Approval

Display Name: Stage Category

stagename

Edm.String

Description: Type a name for the process stage.

Display Name: Process Stage Name

versionnumber

Edm.Int64

Description: Version number of the process stage.

Display Name: Version Number

Read-only property

I will now try to test out the values that I can get from this entity.

More details in this MSDN article:

https://msdn.microsoft.com/en-us/library/mt790421.aspx

Hope this helps someone!

Reply
Verified Answer
Mohamed Mostafa responded on 21 Jun 2017 3:26 AM

I found some additional information (thanks for the tips above from David and Alex).

The Workflow entity stores a business process flow definition. So once the entity is created, it is always in Draft state and its definition is stored in Workflow entity. XAML property is where the definition is stored and is mandatory/required.

Once you activate a business process flow definition (by changing the state of the corresponding Workflow entity record), a custom entity with the following name is automatically created to store the activated business process flow instances: "<activesolutionprefix>_<uniquename>".

Here is the code to retrieve active path for a process and the current and next stages on the process:

// Retrieve the active stage ID of in the active process instance

_activeStageId = new Guid(activeProcessInstance.Attributes["processstageid"].ToString());

// Retrieve the process stages in the active path of the current process instance

RetrieveActivePathRequest pathReq = new RetrieveActivePathRequest

{

   ProcessInstanceId = _processOpp2Id

};

RetrieveActivePathResponse pathResp = (RetrieveActivePathResponse)_serviceProxy.Execute(pathReq);

More details in this MSDN article:

msdn.microsoft.com/.../dn481586.aspx

Workflow entity definition:

msdn.microsoft.com/.../mt622427.aspx

Hope this helps anyone trying to get better understanding of Business Process Flows new Model (version 8.2 December 2016 release. This community discussion is now worth a blog post!

Reply
SB1982 responded on 17 Nov 2017 3:51 AM

Hi Mohamed,

Thank You for the details about the new data model for Business process flows.

I have a requirement from my customer to calculate the duration of sales process stages each user is going through.

eg for all leads qualified as opportunities in 2017: how long were they in Qualify, Discovery, Execution stages etc by owner.

I figured out that achieving this requirement was pretty straight forward to implement in CRM v8.1 or earlier. (below link)

community.dynamics.com/.../how-can-i-work-out-the-time-spent-in-each-stage-of-a-business-process

However from CRM v8.2 onwards, like you pointed out that there has been data model changes in the way the business process works internally...it seems that each BPF spawns a new custom entity..

I was planning to add a custom entity which could track the stage start and end times using a workflow.

However to track the time duration for each stage, I need to know when to trigger my workflow which should ideally happen whenever the BPF starts or stage change happens.

Any ideas, suggestions welcome!

Reply
Verified Answer
Alex Shlega responded on 20 Jun 2017 8:54 AM

Hi Mohammed,

 Not sure about the DB table.. There is processstage entity. You can try this kind of webapi request to see what's in there:

https://<URL>/api/data/v8.2/processstages

 It'll give you all the process stages and steps per stage, it seems.

 Every process flow entity, in turn, will have a lookup to the process stage.

Reply
Verified Answer
Mohamed Mostafa responded on 21 Jun 2017 2:47 AM

Many thanks Alex. This is really helpful. I think this might be the entity I was looking for.

Here is what I found:

Process Stages Entity contains: Step metadata for process stage (Client Data). It also contains stage Category (Qualify, Develop, Propose, etc.) and also Stage Name.

Here is a table of the Entity Properties for SDK calls:

Name

Type

Details

clientdata

Edm.String

Description: Step metadata for process stage

Display Name: Client Data

Read-only property

owningbusinessunit

Edm.Guid

Description: Select the business unit that owns the record.

Display Name: Owning Business Unit

Read-only property

primaryentitytypecode

Edm.String

Description: Primary entity associated with the stage.

Display Name: Primary Entity

processstageid

Edm.Guid

Description: Shows the ID of the process stage record.

Display Name: Process Stage

stagecategory

Edm.Int32

Description: Select the category of the sales process.

Default Options:

0 : Qualify
1 : Develop
2 : Propose
3 : Close
4 : Identify
5 : Research
6 : Resolve
7 : Approval

Display Name: Stage Category

stagename

Edm.String

Description: Type a name for the process stage.

Display Name: Process Stage Name

versionnumber

Edm.Int64

Description: Version number of the process stage.

Display Name: Version Number

Read-only property

I will now try to test out the values that I can get from this entity.

More details in this MSDN article:

https://msdn.microsoft.com/en-us/library/mt790421.aspx

Hope this helps someone!

Reply
Verified Answer
Mohamed Mostafa responded on 21 Jun 2017 3:26 AM

I found some additional information (thanks for the tips above from David and Alex).

The Workflow entity stores a business process flow definition. So once the entity is created, it is always in Draft state and its definition is stored in Workflow entity. XAML property is where the definition is stored and is mandatory/required.

Once you activate a business process flow definition (by changing the state of the corresponding Workflow entity record), a custom entity with the following name is automatically created to store the activated business process flow instances: "<activesolutionprefix>_<uniquename>".

Here is the code to retrieve active path for a process and the current and next stages on the process:

// Retrieve the active stage ID of in the active process instance

_activeStageId = new Guid(activeProcessInstance.Attributes["processstageid"].ToString());

// Retrieve the process stages in the active path of the current process instance

RetrieveActivePathRequest pathReq = new RetrieveActivePathRequest

{

   ProcessInstanceId = _processOpp2Id

};

RetrieveActivePathResponse pathResp = (RetrieveActivePathResponse)_serviceProxy.Execute(pathReq);

More details in this MSDN article:

msdn.microsoft.com/.../dn481586.aspx

Workflow entity definition:

msdn.microsoft.com/.../mt622427.aspx

Hope this helps anyone trying to get better understanding of Business Process Flows new Model (version 8.2 December 2016 release. This community discussion is now worth a blog post!

Reply
Suggested Answer
Mohamed Mostafa responded on 20 Jun 2017 8:24 AM

Thanks David. Just to confirm, you are saying that the Business Process Flow design including stages and steps are still stored in XAML definition under the Workflow entity XAML column.

I would also add that I found out that new data model means that every instance of each Business process flow is stored as a record under the Business Process Flow own entity.

Anyone has any more information to add to this?

Reply