After Business Rule Not Updating Records

Steven McCray1
Giga Guru

Desired Solution: I need a business rule to trigger on the core_company table to glide over to another table and update a value on that table. The matching condition is a value called the 'u_branchkey' which is a 3 digit number.

I've gone through the code a few times, tried a few different solutions but nothing seems to be successful in getting the action to function as expected.

find_real_file.png

 

I've confirmed in my testing, that the field 'u_branchkey' is accurate and exists on both the core_company and the u_agency_it_state_tracker tables. The value is 100 for both, so as far as I understand, the query should be going to the agency table, and finding what matches 100, then proceeding to update that record.

I've successfully been able to create/insert records on the table so I know the communication to the target table isn't hindered (we also have other processes that work and communicate with our agency table).

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You don't need "==" in your business rule script.

Update your code like gr.addQuery('u_branchkey',current.u_bkey);

Also, i hope that this custom branch key field on company table is a reference field to your custom table in which you are updating records.

 

Regards,

Sachin

 

View solution in original post

7 REPLIES 7

Chetan Mahajan
Kilo Sage
Kilo Sage

Hi,

             try below one

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

	var branch_key = current.u_branchkey;
	// var encodedquery = "short_descriptionLIKE"+branch_key;  // if branch key is string field try this instead addQuery
	var gr = new GlideRecord('u_agency_it_state_tracker');
	gr.addQuery('u_branchkey', branch_key);  
	//gr.addEncodedQuery(encodedquery);
	gr.query();
	
	while(gr.next()){
		gr.setValue('u_helpdesk', "onboarded");
		gr.update(); 
	}
	// or use gr.updateMultiple();
})(current, previous);

Yep this solution would have worked as well, thank you for your input, much appreciated!

ahsanulhaq0
Kilo Contributor

Hi everyone,

It sounds like you're facing an issue where your After Business Rule is not updating records as expected. Here's a troubleshooting checklist that might help:

  1. Check Conditions and Filters: Ensure that the conditions in your rule are correct and that they apply to the records you intend to update. Sometimes, a small condition mismatch can prevent the rule from triggering properly.

  2. Use the current.update Command: In After Business Rules, make sure you're explicitly calling current.update. Since it runs after the database action, failing to include this can prevent the record from being updated.

  3. Avoid Recursive Updates: If your rule triggers another update on the same table, ensure it’s not causing a recursive loop. ServiceNow includes safeguards against this, but always check the System Logs to confirm no recursion warnings.

  4. Review Script Logic: Check the script’s logic carefully. A missed line or syntax error could prevent the update from happening.

  5. Verify Field Access: Make sure the user role running the business rule has proper access to update the fields in question.

  6. Check Other Business Rules or Workflows: Sometimes, other business rules or workflows might interfere. Disable them temporarily to see if they’re causing the issue.

  7. Debugging Tools: Use gs.log statements or the Script Debugger in ServiceNow to trace your rule’s execution path.

Feel free to share your rule’s script if you’re still having trouble. I’d be happy to help further!

Best regards,
Ahsan Ul Haq
Griffin Resources