Script is working in background script but not working in Business Rule

Vengeful
Mega Sage

What seems to be the reason why script is working in background script but  not working in Business Rule?

1 ACCEPTED SOLUTION

@Vengeful 

how many records you want to insert sn_grc_issue? 1 or some other value?

try this

(function executeRule(current, previous /*null when async*/ ) {

	var entity = new GlideRecord('sn_grc_profile');
	entity.query();
	while (entity.next()) {
		var issue = new GlideRecord('sn_grc_issue');
		issue.initialize();
		issue.classification = 3;
		issue.short_description = entity.name + ' has a control test failure';
		issue.insert();
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

13 REPLIES 13

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Vengeful ,

 

Can u share what script is not working in BR?

Is the BR getting triggered?

 

Thanks,

Danish

 

AshishKM
Kilo Patron
Kilo Patron

Hi @Vengeful ,

 

Share the fix script code and BR details.

 

-Thanks

Ashish


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Ankur Bawiskar
Tera Patron
Tera Patron

@Vengeful 

Please share the script.

Remember you need to use current object in business rule for the table on which BR is written.

I suspect you might be copying the same background script. ensure you use correct GlideRecord objects.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Vengeful
Mega Sage

Hi @AshishKM @Ankur Bawiskar @Danish Bhairag2 

(function executeRule(current, previous /*null when async*/ ) {

var issue = new GlideRecord('sn_grc_issue');
issue.initialize();
issue.classification = 3;

var entity = new GlideRecord('sn_grc_profile');
entity.query();

while (entity.next()) {
issue.short_description = entity.name + ' has a control test failure';
issue.insert();
}

})(current, previous);
Merza_0-1699506353989.png