Using a business rule to update an incident field

colinmorgan
Kilo Contributor

Good day all,

this is going to be a really silly question but I must be missing something very basic.

I have a customer submitting Incident Requests into my Service Now instance. Their short description comes in as a 4 digit number.

In order for my customer's service management system to recognise my responses as part of that ticket chain they need to see responses come back as ##number##.

I have tried to create a business that fires on insert with a script that looks at the short description field and   then adds the hashes to it. For some reason i can't get it to work.

My script looks like this:

function onBefore(current, previous) {

var desc = current.short_description;

current.short_description = ( '##' + desc + '##');

current.update();

}

thank for for you help.

Colin

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Colin,



I just tried and your code works.


However please remove the line "current.update()" from the BR



NOTE : Avoid using current.update() in a business rule script. The update() method triggers business rules to run on the same table for insert and update operations, leading to a business rule calling itself over and over. Changes made in before business rules are automatically saved when all before business rules are complete, and after business rules are best used for updating related, not current, objects. When a recursive business rule is detected, the system stops it and logs the error in the system log. However,current.update() causes system performance issues and is never necessary.


Abdul Khan4
Kilo Guru

Solution given by Pradeep works.


Also, You can use Business Rule as "after insert"


Hi Abdul,



I would not recommend to use after insert in this case. after business rules are best used for updating related, not current, objects.


Please let me know if you have any questions.


Thanks Pradeep,



it does actually work. What i actually discovered on the back of your response is that it was an issue with the order of execution of the business rule. I increase the order of my business rule and then it worked fine.



Many thanks for your help.



Colin