"activity.result" workflow condition is not following the desired path

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 08:07 AM
Hello Everyone,
I am trying to move a change request to a previous state by deleting/cancelling existing approvals of current state and setting previous state approvals to 'requested' state. To achieve this I have created UI Action called 'Revert to previous state' , on click of that button system will revert change request to previous state and it will set all previous state approvals to 'Requested' state.
In UI Action, I am fetching executing workflow activity and setting activity result to 'previous' and activity state to 'finished'. Here is the sample code snippet of UI Action
Created new workflow condition called 'Previous' . Please refer below snapshots for reference
And on click of 'Revert to previous state' system is finishing the 'Approval Group' activity and result of activity is getting set to 'previous' but system is not following the desired path. I mean it is not traversing from 'Previous' output to 'Rollback to' activity. Here is the result of that activity
I referred below article but could not find the solution.
Using Rollback To with multiple branches.
Please guide me here.
Thanks & Regards,
Abhinandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 03:45 PM
I definitely don't recommend altering wf_executing records with script. Are you doing that because something else isn't working or is your solution primarily designed on assuming that you can do that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 02:19 AM
Hi Matthew,
Thanks for your response. Yes I assumed that this can be achieved.
We have different set of approvals at every stage. And the requirement is to revert a change request to previous state using a button. On click of that button system should delete/cancel approvals of current state & move it to previous state. Along with this, system should reset approvals [reset approvals to 'Requested' state] of previous state.
To achieve this I thought of using 'Rollback To' activity and UI Action. Now to relate UI Action and 'Rollback To' activity of workflow,I have created new workflow condition called 'Previous' on 'Approval Group' activity [refer attached snapshots]. I am trying to set the activity result to 'previous' in UI Action so that control moves to 'Rollback To' activity from 'Previous' workflow condition. But for some reason control is not moving forward from 'Previous' workflow condition.
After execution if I hover the activity [refer screenshot], I see that 'Ended' parameter remaining empty even though I am updating 'Ended' parameter while creating 'Workflow history' using 'createHistory()' method. Is this the reason for this behavior?
I would be glad if you can provide me some solution here or an alternative solution.
Thanks & Regards,
Abhinandan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 07:30 AM
I agree, don't mess with wf_context. Let it do it's thing. Normally, the Rollbackto will reset the approvals (if used properly) and you can insert a Set Values activity to change the state to what you want. Let the approval drive the roll back, not a UI action.
You might find episode 9 of TechNow helpful. It deals with a similar requirement for more information on an approval.
Coordinating activities between UI actions and workflows is a tricky proposition. I generally don't recommend it for "going back". You may want to cancel the workflow (using Workflow().cancel()) from your UI action or Workflow().restartWorkflow()
https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_Workflow_Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 09:22 AM
What about this? You create a UI Action that is a copy of the "Reject" action except for two things:
1) It sets an additional hidden field value called u_rollback_needed to true
2) It is visible to any user who can see the form
By rejecting the approval, this will progress the workflow to the next level. The next activity in the flow will be an activity that does one of two things:
1) If u_rollback_needed is true, resets u_rollback_needed to false and then goes to a Rollback activity
2) If u_rollback_needed is false, continues on the normal path