JavaScript condition examples

The predefined workflows for cases, solutions, opportunities, and leads contain examples of Javascript conditions.

Entity name

Rule name

Example script

Opportunity

Reassign
Copy
Valid = (oppo_stage != 'Closed');
Cases Reassign
Copy
Valid = ((case_stage!='Closed') && 
(case_stage != 'Logged') && (case_stage!='Investigating'));
Lead Reassign Lead
Copy
Valid=(lead_status == 'In Progress');
Lead Edit Lead
Copy
Valid=(lead_status == 'In Progress');

You can directly reference the fields of the workflowed record and return the field value. You cannot directly reference the fields of other records that are in context of the workflowed record. Instead, you can use CRM.GetContextInfo() to reference these fields and get data that's in context of the workflowed record.

You can use these techniques on custom entities to reference the fields of the workflowed record and return the field value.

The following is an example JavaScript condition on a custom entity called Project:

Copy
if (proj_stage != 'Planning')
    {
        Valid = false;
    }

The following is an example JavaScript condition on a custom entity called Project that's a child of Company:

Copy
if (proj_stage == 'Planning' && CRM.GetContextInfo("company","comp_type")=='Customer')
    {
        Valid = false;
    }
    
else
    {
        Valid = true;
    }