We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

ITSM

surajsengar
Kilo Guru

How should I design a Business Rule to update a field automatically?

2 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron

https://www.servicenow.com/community/developer-forum/updating-the-field-value-using-business-rule/m-...

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

Kamva
Giga Guru

You can use a Business Rule to update the field automatically when a record is created or updated.

Steps:

  1. Go to System Definition → Business Rules.

  2. Create a new Business Rule on the required table.

  3. Set When to Before and choose Insert and/or Update depending on when you want it to run.

  4. Add a Condition if the update should only happen under certain circumstances.

  5. In the Script, set the field value.

Example:

(function executeRule(current, previous) {
    // Automatically set var to 'new value'
     current.var = 'new value';
})(current, previous);

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron

https://www.servicenow.com/community/developer-forum/updating-the-field-value-using-business-rule/m-...

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Kamva
Giga Guru

You can use a Business Rule to update the field automatically when a record is created or updated.

Steps:

  1. Go to System Definition → Business Rules.

  2. Create a new Business Rule on the required table.

  3. Set When to Before and choose Insert and/or Update depending on when you want it to run.

  4. Add a Condition if the update should only happen under certain circumstances.

  5. In the Script, set the field value.

Example:

(function executeRule(current, previous) {
    // Automatically set var to 'new value'
     current.var = 'new value';
})(current, previous);

yashkamde
Kilo Sage

Hello @surajsengar ,

 

Configure Before Insert/Update BR on the target table.

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

    if (condition) {
        current.active = true;
    }

})(current, previous);

 

Note : Using a Before BR is considered best practice because it avoids additional database updates and improves performance.

If my response helped mark as helpful and accept the solution.

Aditya_hublikar
Mega Sage

Hello @surajsengar ,

 

Use before update/insert business rule , add required condition then use below code snippet

(function executeRule(current, previous) {
     current.your_variableName = RequiredValue;
})(current, previous);

When you use before update/insert business rule, at that time above logic will set required value and it will inserted/updated automatically.

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya