''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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is the 'Auto assessment business rule' not working for any survey or only for your custom survey?

Regards
Ankur

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

For my survey and again after this I tried to create another survey and added a trigger condition for this also it is not working But surveys that are already there for them the Bussiness rule is there .

Hi,

Did you check the survey trigger condition got matched?

Regards
Ankur

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

Hi,

Yes, All that trigger conditions got matched but in the trigger condition the bussiness rule field is empty for now whic should be auto created.