Controlling Workflow Availability

2 minute read time.
Imagine a system where you may want to ensure that your users do not create any new support cases for a company that has had their status changed to "On Hold".

The ideas discussed here would also apply to any record created as a child of a company or a person. In your own systems you may have the requirement to prevent sales opportunities being recorded against customers who have poor credit ratings. If you have added a custom entity to the system this concept applies also.

In the example system the logging a new case is controlled by the workflow. We therefore will have to change the workflow to stop users creating records when they should not.

Note:

A case can be created by a user clicking either the 'New' button on the case list screen that is called from the 'My CRM' and 'Team' menus. The case list also is called from the tab bar of the company and person summary screens.

The New button also appears in the 'New' main menu option.

Assumption:

In this example I assume that the "On Hold" flag is set in the company status field, comp_status.

Using the Javascript Condition to Control Primary Rule Availability

The JavaScript Condition field on Primary, Transition, Conditional, and Global rules limits whether or not the rule appears for a given record.

To hide the 'New' button on the case list called from the company and person tab bars (where the company is "on hold") I can add to the Primary rule of the case workflow the following javascript condition:


var strStatus = eWare.GetContextInfo("company", "comp_status"); 
if (strStatus == "On Hold") 
{ 
Valid = false; 
} 
else 
{ 
Valid = true; 
}


The method GetContextInfo can be used here because the company entity is in context.

The Main Menu New Button

The above example will not hide the New Button that is called from the Main Menu, nor will it hide the New Button on the 'My CRM' nor the 'Team' menus.

This is because the customer may not be known until the user chooses it in the company field of the case entry screen and confirms it using the Save button.

In this example to stop the users creating a support case for a customer that is "On Hold" we need to use a validation rule.

This example validation rule can be added to a field such as case_referenceid that appears in the casedetailbox screen.

This validation rule will also act as a double check to the first example given.

 
intCompID = Values("case_primarycompanyid"); 
var recComp = eWare.FindRecord("company", "comp_companyid ="+intCompID); 
if (recComp.comp_status=="On Hold") 
{ 
Valid = false; 
ErrorStr = "You may not create a case for a company placed on hold."; 
}