Why isn't a Business Rule (BR) Running when Inserting Via Script in a Workflow?

Joshua Cassity
Kilo Guru

Hello there,

We are taking a stab at automating our billing process and the approach we've taken is at the end of each service offering's workflow we place a 'Run Script' activity that will generate a line item in our billing repository table. We are doing that as such:

// Initialize a record into the Billing Repository.

var bill = new GlideRecord('u_enterprise_billing_repository');

bill.initialize();

bill.u_record_number = current.sys_id;

bill.u_customer_id = current.variables.u_username.user_name;

bill.u_customer_name = current.variables.u_username.first_name + ' ' + current.variables.u_username.last_name ;

bill.u_service_item = 'JVPN(' + current.variables.u_username.user_name + ')';

bill.u_service_code = 'JVPN';

bill.u_action = 'Add';

bill.u_speed_chart = current.variables.u_speedchart;

bill.insert();

And that insert is working great with no issues. However, on this table we have two business rules that are set to 'Before' an 'Insert/Update' that go query the record number (in our case a RITM number) and then pull it's closed date to populate a field and then another BR to calculate when we are going to bill based upon that date - before the 15th, the first of the current month & after the 15th, the beginning of the next month.

These business rules work great upon a manual insert or a manual update of records into the table;however, they are not working / triggered upon the initial creation of the record using the scripted activity inside the workflow of the catalog item.

Anyone have any ideas on this? Am I going to have to instead take these scripts and make them a scheduled job?

1 ACCEPTED SOLUTION

Ended up using a Scheduled Job and that fixed the issue since the billing records were being created in the workflow and technically the parentrecords had not closed yet. Thanks all for the suggestions.


View solution in original post

11 REPLIES 11

Hi Joshua,



Try adding log statements and check if business rule is triggering.


Also check when the business rule is executing in particular user session from workflow whether that user has access to create new records in the table you are inserting the records.



Regards


Ankur


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

I'm doing this as myself so I'm able to create new records as an admin. I've put in a Hi incident but will try to log a run as well and see.


Very odd.. it appears that it is in fact running / being triggered per the log. Interesting.


Hi Joshua,



Can you add log inside of while loop and see ?


I suspect addQuery condition having issue.


Please run same query in the background script by mentioning the number directly and in the   If/while , just add log to see if it is able to filter the records.



Thanks,


Rajesh T


We've found that all our Closed dates are empty.. that's why it's not populating the field.



I thought Closed was a system timestamp.




~ J ~