Building a Workflow Map Diagram that Shows Progress through Workflow

3 minute read time.

Workflows in Sage CRM can become long and a user may wish they had a version of the diagram that is available when the workflow is constructed. You can see from this image below that an extra button has been added to the Opportunity screen.

In this example application, when the 'Workflow Map' button is clicked, the current opportunity is checked to see if the record belongs to an workflow. It the opportunity is attached to a workflow it determines which workflow has been used and produces a diagram. The current workflow state is then highlighted (in red) in the created diagram. The user is also given a primt button which will allow the page to be printed and a continue button that will return the page to the opportunity summary page.

An entity like opportunity may have multiple workflows available to it. But an individual opportunity record may be attached to only one workflow. The example custom page used here will detect which workflow diagram should be displayed.

Recreating this Feature

Note: Due to authorization requirements this feature needs to be restricted to either Info Managers with Workflow Rights or Full System Administration rights. This is controlled within the area

Administration -> Users -> Users

Building the Button

The button on the Opportunity Summary screen has been built by creating a new Button Group for the Opportunity Summary system action.

Administration -> Advanced Customization -> Button Groups

To ensure that the button only displays when

  1. The Opportunity is attached to a workflow and
  2. The User has the correct rights (either Info Admin with Workflow or Full Administrator)

The following Tab SQL Clause has been used:


oppo_workflowid is not null; user_per_infoadmin like '%user_per_workflow%' or user_per_admin=3

The Tab option calls the ASP page "showworkflow.asp".

The ASP Page

The code for the ASP page is show here:



"2": strEntity="person";
break;
case "6": strEntity="communication";
break;
case "7": strEntity="opportunity";
break;
case "8": strEntity="cases";
break;
case "68": strEntity="solutions";
break;
default: strEntity="";
}
//get workflow information
var TableRecord = CRM.FindRecord("custom_tables","bord_name='"+strEntity+"'");
var intWorkflowInstId = CRM.GetContextInfo(strEntity,TableRecord.bord_workflowidfield);
var WorkflowRecord = CRM.FindRecord("workflowinstance","wkin_instanceid="+intWorkflowInstId);
var intWorkflowId = WorkflowRecord.wkin_workflowid;
var WorkflowStateRecord = CRM.FindRecord("workflowstate","wkst_stateid ="+WorkflowRecord.wkin_currentstateid);
var strWorkflowState = WorkflowStateRecord.wkst_name;
//build path to diagram
//workflow diagram action is 1308
var strPath = new String(Request.ServerVariables("HTTP_REFERER"));
var arrayContext = strPath.split("?");
var strContextInfo = arrayContext[0];
var strSID = new String(Request.QueryString("SID"));
var strFullPath= strContextInfo+"?SID="+strSID+" &Act=1308 &Mode=1 &CLk= &Key0=47 &Key47="+intWorkflowId+" &ex= &Err=";
//build 'wakeup' path
//this is needed to set the system ready to return the diagram
var strWakeUpPath= strContextInfo+"?SID="+strSID+" &Act=428 &Mode=1 &CLk= &Key0=47 &Key47="+intWorkflowId+" &ex= &Err=";
//issue 'wakeup' call to CRM
var xml, text
//Instantiate the Object to carry out the XML request.
xml = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xml.open("GET", strWakeUpPath, 0);
//Response.Write(strWakeUpPath);
xml.send("");
//fetch the workflow diagram
//Instantiate the Object to carry out the XML request.
//xml = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xml.open("GET", strFullPath, 0);
//Response.Write(strFullPath);
xml.send("");
var text = String(xml.responseText);
xml = "";
//format the returned HTML to strip out unwanted buttons etc
var arrayTextByBody = text.split("");
if (arrayTextByBody[1])
{
var intPosBodyClose = arrayTextByBody[1].indexOf(">");
var strTextStrippedofBody = arrayTextByBody[1].substr(intPosBodyClose+1);
var arrayTextByEndBody = strTextStrippedofBody.split("");
var strDiagram = arrayTextByEndBody[0];
//add in highlight for current state
var searchExpression = new RegExp(strWorkflowState, "gi");
var strHighlighting = ""+strWorkflowState+"";
var strDiagram = strDiagram.replace(searchExpression, strHighlighting);
}
else
{
var strDiagram = "Time Out Error";
}
var contentBlock = CRM.GetBlock("content");
contentBlock.contents = strDiagram;
var myBlockContainer = CRM.GetBlock("Container");
var strPrintButton = CRM.Button("print", "print.gif", "javascript:window.print()");
var strContinueButton = CRM.Button("continue", "continue.gif", Request.ServerVariables("HTTP_REFERER"));
with (myBlockContainer)
{
AddBlock(contentBlock);
DisplayButton(Button_Default) = false;
AddButton(strContinueButton);
AddButton(strPrintButton);
}
CRM.AddContent(myBlockContainer.Execute());
Response.Write(CRM.GetPage());
%>


Notes

  1. The Page is designed to be reused in any of the main system entities that use Workflow. At the beginning of the code there is a switch case statement that is used to detect which context the page is being used in.
  2. The page uses a serverside HTTP request to fetch the diagram from within CRM. The diagram is part of the workflow administration screens.
  3. Two web requests have to be made to produce the diagram, this is because the diagram is not usually expected to be called except within the system administration screens.
  4. The HTML returned has to be processed to removed the edit buttons.
  5. The current workflow state is then highlighted by adding additional style information into the HTML.
  6. The diagram HTML is added to a CRM content block and in turn is added to a container.
  7. The print and the continue buttons are added to the contain and the page is returned.
Parents Comment Children
No Data