A Universal "Go Back" button in Workflow

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

A Universal "Go Back" button in Workflow

  • Comments 2
  • Likes
The requirement to allow the user to fall back to an earlier point in the workflow is usually handled by looping. We can see from the diagram below how a workflow can allow a user to drop back and repeat or cycle through certain workflow states again and again. 

But what if we need to have a workflow rule available to a user to allow them to repeat any step?

In the image below we can see the user has progressed the opportunity to the "Qualified" state. There is a button indicating that we can fall back to the previous workflow state. This article is a discussion of how the creation of a "Go Back" button could be implemented. It is not a tested worked solution!

I created this feature using a global rule that calls an ASP page.

To allow the workflow rule to reset the workflow state we must know what state to return to. Workflow state for a record is held in the workflowinstance table. An article that discusses the role of the workflowinstance table is "Controlling workflow state in ASP". 

In our example we will need to store the previous workflow state for a record in a new field.

I added a field called oppo_oldworkflowstateid. In the example I updated the field within the workflow actions rules associated with the transition rules.

The create script sets the field value.

var intRecordId = CRM.GetContextInfo("opportunity","oppo_workflowid");
var myRecord = CRM.FindRecord("workflowinstance","wkin_instanceid="+intRecordId);
DefaultValue = myRecord.wkin_currentstateid;

But this update could also have been done using a UpdateRecord() event function in a tablelevel script.

Note: The requirement to keep track of the previous workflow state means that much thought and testing will have to go into the mechanism used to store the previous state. This could become expensive in time in a complex workflow.

The Global rule would need to make use of a JScript condition that ensured the rule was available to users only when it was appropriate.

My ASP page is very simple and contains the script:

var intRecordId = CRM.GetContextInfo("opportunity","oppo_workflowid");
var myRecord = CRM.FindRecord("workflowinstance","wkin_instanceid="+intRecordId);
myRecord.wkin_currentstateid = CRM.GetContextInfo("opportunity","oppo_oldworkflowstateid");
// Call Other action to undo previous rules actions

The code finds the workflowinstance record associated with the current entity and resets the workflow state to the value held in the oppo_oldworkflowstateid field. It then redirects the screen back to the opportunity summary screen.

Note: The major flaw with a "Go Back" button is that the previous workflow rules may have carried out tasks that can not be undone e.g. emails once sent can not be unsent.
  • Can the same result be achieve this with the clientside api?

  • Adam

    I would not be easy.  You would still have to invoked behaviour that was executed on the server to make the change to the workflowinstance table.  This is not a table that is exposed to SData or web services by default.