Insert Business rule not running in the headless tests execution

Juhitha
ServiceNow Employee
ServiceNow Employee

I have a business rule that is triggered on inserting a record in "interaction_related_record" table.

 

Juhitha_0-1726038654771.png

 

 

As part of the headless test, I am creating a record using script below

 


GlideRecord caseGr = new GlideRecord("sn_customerservice_case");
caseGr.setValue("short_description","Test case");
String caseSysId = caseGr.insert();

GlideRecord interactionRelatedRecordGr = new GlideRecord("interaction_related_record");
interactionRelatedRecordGr.initialize();
interactionRelatedRecordGr.setValue("interaction", interactionSysId);
interactionRelatedRecordGr.setValue("document_table","sn_customerservice_case");
interactionRelatedRecordGr.setValue("document_id",caseSysId);
interactionRelatedRecordGr.setValue("task", caseSysId);
interactionRelatedRecordGr.setValue("type", "task");
interactionRelatedRecordGr.setValue("operation", "Created");
interactionRelatedRecordGr.insert();

 

After running the test, the records are getting inserted in the tables, but the BR is not getting executed. Can anyone help me in understanding what can be the reason? 

1 REPLY 1

Community Alums
Not applicable

Hi @Juhitha ,

Please make change in BR instead of After make in before and add below code 

var caseGr = new GlideRecord("sn_customerservice_case");
var caseSysId = caseGr.initialize();
caseGr.setValue("short_description","Test case");
caseGr.insert();

var interactionRelatedRecordGr = new GlideRecord("interaction_related_record");
interactionRelatedRecordGr.initialize();
// interactionRelatedRecordGr.setValue("interaction", interactionSysId);
interactionRelatedRecordGr.setValue("document_table","sn_customerservice_case");
interactionRelatedRecordGr.setValue("document_id",caseSysId);
interactionRelatedRecordGr.setValue("task", caseSysId);
interactionRelatedRecordGr.setValue("type", "task");
interactionRelatedRecordGr.setValue("operation", "Created");
interactionRelatedRecordGr.insert();

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak