Controlling Workflow Availability

Hints, Tips and Tricks

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

Controlling Workflow Availability

  • Comments 2
  • Likes
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."; 
}
Comments
  • Is there a reason that this would not work at all with version 7.2? I have a requirement to make the new opportunity button hidden in any non-job context (job being a new custom entity). I am trying to work my way from the sample code here to be able to serve this requirement, but even if the only line of code I leave in the javascript for the primary rule is " Valid = false; ", the New Opportunity button remains on all screens for all users.

  • This has been mention in the forums:  community.sagecrm.com/.../29578.aspx

    I've logged a case internally but it is a good idea for you to log a case too.