''Auto assessment business rule'' not created for trigger condition of Survey in DEV.

Rushikesh3
Tera Contributor

When we create a survey to trigger it we have given a trigger condition but in that the 'Auto assessment business rule' Bussiness rule which should auto generate but is not generating OOB. And when we try to create and attache it it is not working for custom bussiness rule.

   Please help if any solution you have.

Thank you.

1 ACCEPTED SOLUTION

@Rushikesh 

Glad that the approach I shared helped you debug.

Why is it missing?

It is out of the box and should be present unless someone removed it manually.

Please find the function below and add it to the script include

updateTriggerConditionBR: function(triggerCondition) {
		var override = '';
		
		if (!triggerCondition.business_rule.nil()) {
			var pMgr = new GlidePluginManager();
			var isDomainSeparationActive = pMgr.isActive('com.glide.domain.msp_extensions.installer');
			if (isDomainSeparationActive) {
				var userDomain = gs.getUser().getDomainID();
				userDomain = userDomain || 'global'; // if user domain is null, use global
				if (userDomain != triggerCondition.business_rule.sys_domain) {
						override = triggerCondition.business_rule + '';
						triggerCondition.business_rule = '';
				}
			}
		}
		var escapeCondition = triggerCondition.condition.toString();
		escapeCondition = escapeCondition.replace(/[\'\"]/g, "\\'");
		var brCondition = "(new global.AssessmentUtils().conditionCheck(current, '" + escapeCondition + "'))";
		var br;
		
		if (!triggerCondition.business_rule.nil())
			br = triggerCondition.business_rule.getRefRecord();
		
		else {
			br = new GlideRecord('sys_script');
			br.initialize();
		}
		br.name = 'Auto assessment business rule';
		br.action_insert = true;
		br.action_update = true;
		br.active = true;
		br.when = 'after';
		br.execute_function = true;
		br.order = 300;
		br.collection = triggerCondition.table;
		if (brCondition.length <= 254) {
			br.condition = brCondition;
			br.script = "function onAfter(){ \n (new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '" + triggerCondition.sys_id + "'); \n }";
		} else {
			br.condition = "";
			br.when = "after";
			br.script = "function onAfter(){ \n if (" + brCondition + ") \n (new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '" + triggerCondition.sys_id + "'); \n }";
		}
		if (override)
			br.sys_overrides = override;
		if (triggerCondition.business_rule.nil()) {
			var brId = br.insert();
			triggerCondition.business_rule = brId;
			triggerCondition.setWorkflow(false);
			triggerCondition.update();
			triggerCondition.setWorkflow(true);
		} else
			br.update();
	},

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

14 REPLIES 14

@Rushikesh 

Glad that the approach I shared helped you debug.

Why is it missing?

It is out of the box and should be present unless someone removed it manually.

Please find the function below and add it to the script include

updateTriggerConditionBR: function(triggerCondition) {
		var override = '';
		
		if (!triggerCondition.business_rule.nil()) {
			var pMgr = new GlidePluginManager();
			var isDomainSeparationActive = pMgr.isActive('com.glide.domain.msp_extensions.installer');
			if (isDomainSeparationActive) {
				var userDomain = gs.getUser().getDomainID();
				userDomain = userDomain || 'global'; // if user domain is null, use global
				if (userDomain != triggerCondition.business_rule.sys_domain) {
						override = triggerCondition.business_rule + '';
						triggerCondition.business_rule = '';
				}
			}
		}
		var escapeCondition = triggerCondition.condition.toString();
		escapeCondition = escapeCondition.replace(/[\'\"]/g, "\\'");
		var brCondition = "(new global.AssessmentUtils().conditionCheck(current, '" + escapeCondition + "'))";
		var br;
		
		if (!triggerCondition.business_rule.nil())
			br = triggerCondition.business_rule.getRefRecord();
		
		else {
			br = new GlideRecord('sys_script');
			br.initialize();
		}
		br.name = 'Auto assessment business rule';
		br.action_insert = true;
		br.action_update = true;
		br.active = true;
		br.when = 'after';
		br.execute_function = true;
		br.order = 300;
		br.collection = triggerCondition.table;
		if (brCondition.length <= 254) {
			br.condition = brCondition;
			br.script = "function onAfter(){ \n (new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '" + triggerCondition.sys_id + "'); \n }";
		} else {
			br.condition = "";
			br.when = "after";
			br.script = "function onAfter(){ \n if (" + brCondition + ") \n (new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '" + triggerCondition.sys_id + "'); \n }";
		}
		if (override)
			br.sys_overrides = override;
		if (triggerCondition.business_rule.nil()) {
			var brId = br.insert();
			triggerCondition.business_rule = brId;
			triggerCondition.setWorkflow(false);
			triggerCondition.update();
			triggerCondition.setWorkflow(true);
		} else
			br.update();
	},

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Will it get change during upgrade?

Yes it will be skipped during upgrade if you update the OOB.

But there is this way to allow this component to get updated when the next upgrade happens

Overwrite customizations during an upgrade

Procedure

  1. Open the customized object (for example, the ArrayUtil script include).
  2. Right-click the header and select Show Latest Update.
  3. Configure the form to add the Replace on upgrade field, if necessary.
  4. Select the Replace on upgrade check box and click Update.
    The customized object will be replaced on the next upgrade.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I have a similar issue. I have one Survey that has two triggers, but the auto assessment business rule only looks at one of the triggers. How do we make it look at both? The survey should fire for different triggers: 

Trigger 1: certain HR Services; recipient: opened_for

Trigger 2: different HR Services: recipient: subject_person

Only the second trigger is being passed to that BR but we need the other one to go also. Why have multiple triggers if the BR only uses the first one you create? 

@Rushikesh

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader