Home > Forum > Rules, JS, SQL > Business rule to give the last transition path

Business rule to give the last transition path
0

Hi there,

is there an easy way to get the ID of the last path passed?
I want to create a rule that decides whether an action template is executed or not, depending on which path the element "travelled" last.

Kind regards,
Klaus

MVP

Hi Klaus,

while the answers of Krystian and Jacek are both valid options I want to add something:

- It may be necessary to check whether you get the expected value in the trigger. There's a chance that you may get different values in the OnExit, OnPath and OnEntry trigger.
- If you have a flow control, and you want to get the path the user clicked on you need to exclude the path triggered by the flow control. The SQL below can be used in a global business rule
- Sometimes it will be easier to have a technical field in which you store the id of the travelled path. I used this approach when there was a workflow which moved the instance from different steps to a "review" step which again had the option to move to a "review 2" step. The reviews could be moved back and forth and in the end the workflow should be moved back to the original step, which started the review. While it would somehow be possible using the existing data, it would have been way more complicated.

Best regards,
Daniel


select Top 1 PathId
from

(
select ROW_NUMBER() Over (order by (select 1)) as Id,
Item as PathId,
(select PATH_STPID from WFAvaiblePaths where PATH_ID = Item) as StepId
from dbo.SplitToTable((select WFD_HistoryPaths from WFElements where WFD_ID = {WFD_ID}),';')

) as paths
where StepId in
-- Only steps which are not flow control steps need to be considered
(select WFSteps.STP_ID from WFSteps where STP_TypeId <> 7 )
order by paths.Id desc

In reply to: Daniel Krüger (Cosmo Consult)

Hi Klaus,

while the answers of Krystian and Jacek are both valid options I want to add something:

- It may be necessary to check whether you get the expected value in the trigger. There's a chance that you may get different values in the OnExit, OnPath and OnEntry trigger.
- If you have a flow control, and you want to get the path the user clicked on you need to exclude the path triggered by the flow control. The SQL below can be used in a global business rule
- Sometimes it will be easier to have a technical field in which you store the id of the travelled path. I used this approach when there was a workflow which moved the instance from different steps to a "review" step which again had the option to move to a "review 2" step. The reviews could be moved back and forth and in the end the workflow should be moved back to the original step, which started the review. While it would somehow be possible using the existing data, it would have been way more complicated.

Best regards,
Daniel


select Top 1 PathId
from

(
select ROW_NUMBER() Over (order by (select 1)) as Id,
Item as PathId,
(select PATH_STPID from WFAvaiblePaths where PATH_ID = Item) as StepId
from dbo.SplitToTable((select WFD_HistoryPaths from WFElements where WFD_ID = {WFD_ID}),';')

) as paths
where StepId in
-- Only steps which are not flow control steps need to be considered
(select WFSteps.STP_ID from WFSteps where STP_TypeId <> 7 )
order by paths.Id desc

Thanks to all three of you!

Finally I used Jacek's solution as I had a brain twist. Thus the "current path" didn't work as I was in another WF Element which was easy to overcome with his solution.

Kind regards,
Klaus