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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Joshua,



Can you check the business rule condition when it is to be triggered.


Also check gs.getsession().isinteractive() is added to your business rule.


if added then it won't run the business rule when record is inserted from backend



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Joshua Cassity
Kilo Guru

There's no condition on it. I have it running every time upon an insert / update.



I'll add the 'gs.getsession().isinteractive()' into the Business Rule script and see if that fixes it.


Hi Joshnua,



no you need not add that to your business rule condition. i just wanted to check what condition is present and whether that line of code was present in condition or not for that BR.



Regards


Ankur


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

find_real_file.png


find_real_file.png



I don't have any conditions at all.