Scripting Escalation Rules in a Component

1 minute read time.
I found this a very interesting issue. If you have created an escalation rule outside a workflow you will not be able to find a place where the component manager script can be generated. So how or where can you get the script of an escalation rule that was created outside a workflow?

If an escalation rule is added to the system only the translation (custom_captions) entry is recorded into the component. This is because the workflow tables are not part of the core meta data. The tables all have the xxxx_component column to store a row's membership of a component.

If you want a workflow to be included in a component, then the component manager script can be generated by opening the workflow's graphical view and clicking the "Preview List" button on the right hand side.

BUT this does not help for individual Escalation Rules. You will have to create the component script code for your self. This is a little trick but not too hard.

Below is the component manager code that will create a free standing escalation rule called "testescalation".

Hopefully you can see how to change this as needed.



//code to add the name of the workflow rule

FamilyType='Tags';
Family='WorkflowRule';
Code='TestEscalation';
Captions['US']='TestEscalation';
AddCaption();

//code to add the rule

var jRuleId10130 = AddCustom_Data('WorkflowRules',
'WkRl', 'WkRl_RuleId', 'WkRl_Entity,WkRl_Caption,
WkRl_RuleType,WkRl_Image,WkRl_Table,
WkRl_WhereClause,WkRl_Channel,WkRl_CustomFile,
WkRl_Order,WkRl_JavaScript,WkRl_Cloneable','
"Opportunity","TestEscalation","Time",
"WorkflowDefault.gif","Opportunity","oppo_stage =
\x27Lead\x27 and oppo_assigneduserid=#U","","",,"","",'
,'1,2,3');

RunSql('IF NOT EXISTS (SELECT WkRl_ActionGroupId
FROM WorkflowRules WHERE
WkRl_RuleId = ' + jRuleId10130 + ' AND
WkRl_ActionGroupId IS NOT NULL) BEGIN
UPDATE WorkflowRules SET WkRl_ActionGroupId = ' +
jRuleId10130 + ' WHERE
WkRl_RuleId = ' + jRuleId10130 + ' END');

RunSql('DELETE FROM WorkflowActions WHERE
WkAc_ActionId IN
(SELECT AcLi_ActionId FROM WorkflowActionLinks
WHERE AcLi_ActionGroupId =
(SELECT WkRl_ActionGroupId FROM WorkflowRules
WHERE WkRl_RuleId = ' +
jRuleId10130 + ' ))');
//RunSql('DELETE FROM WorkflowActionLinks
WHERE AcLi_ActionGroupId =
(SELECT WkRl_ActionGroupId FROM WorkflowRules
WHERE WkRl_RuleId = ' +
jRuleId10130 + ' )');

var jActionId = AddCustom_Data('WorkflowActions',
'WkAc','WkAc_ActionId', 'WkAc_Action,WkAc_Field,
WkAc_Value,WkAc_Attributes,WkAc_NewLine,
WkAc_RowSpan,WkAc_ColSpan,WkAc_Table,
WkAc_EmailTo,WkAc_EmailBCC,WkAc_EmailSubject,
WkAc_EmailBody,WkAc_Order,WkAc_Condition','
"notify","","OppoTest",
"","","","","Opportunity","","","","","","",','');

var LinkId = AddCustom_Data('WorkflowActionLinks',
'AcLi','AcLi_ActionLinkId','AcLi_ActionGroupId,
AcLi_ActionId',-1+','+jActionId+',','');

RunSql('UPDATE WorkflowActionLinks SET
AcLi_ActionGroupId = (SELECT WkRl_ActionGroupId FROM
WorkflowRules WHERE WkRl_RuleId = ' + jRuleId10130 + ')
WHERE AcLi_ActionLinkId = ' + LinkId);