script on incident

AfifU
Kilo Contributor

An Incident is updated from the UI. There is:

an onSubmit Client Script that sets a field value, and

a Before Business Rule on the same table that also updates that field.

Question:
Which one runs first, and which value is finally saved to the record?

Thanks in advance!

4 REPLIES 4

adityahubli
Giga Guru

Hello @AfifU ,

First, the Client Script executes on form submission and updates the field values on the client side. Then, before the record is stored in the database, the Before Business Rule executes on the server side. Although both scripts run, the Business Rule determines the final value that gets saved in the database.

 

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

Regards,

Aditya,

technical consultant

Ankur Bawiskar
Tera Patron
Tera Patron

@AfifU 

it's an easy question.

the final outcome will be based on login in Before Business rule

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Chaitanya ILCR
Mega Patron

order of execution.png

 

Hi @AfifU ,

The onSubmit script runs first on the client and Before BR runs next before data gets stored in the server

the Value set By the BR will be saved.

 

This pic should help you

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Shashank_Jain
Kilo Sage

Hi @AfifU ,

Just a simple explanation to make things clear:

 

When a record is updated from the UI, ServiceNow executes scripts in the following order:

onSubmit Client Script

  • Runs first

  • Executes on the client side (browser)

  • Sets or modifies field values on the form

  • These values are then sent to the server as part of the submit request

Before Business Rule

  • Runs after the request reaches the server

  • Executes on the server side

  • Runs just before the record is written to the database

  • Can validate or override any field values

Final Result

The value set in the Before Business Rule is what gets saved to the record.
This is because server-side scripts always have the final authority, ensuring data integrity and consistency

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain