script on incident

AfifU
Tera 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!

6 ACCEPTED SOLUTIONS

VaishnaviK43271
Tera Contributor

Hi @AfifU !!

  • Runs first: the onSubmit Client Script

  • Value that is finally saved: the value set by the Before Business Rule

Explanation:

  1. When a user submits the Incident form, the onSubmit Client Script runs in the browser first. Any field values it sets are included in the data sent to the server.

  2. After the data reaches the server, the Before Business Rule runs before the record is written to the database.

  3. If the Business Rule updates the same field, it overwrites whatever value was set by the client script.

Result:
 The Before Business Rule’s value is what gets saved to the record.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for.

Thank You

View solution in original post

its_SumitNow
Kilo Sage

replycomm.png

Your Client script is executed first, And then Business rules will run

refer this article:

 https://www.servicenow.com/docs/bundle/zurich-servicenow-platform/page/administer/service-administra...

 

If my response helps, please mark it as helpful and accept as solution

Warm Regards

Sumit Yadav

Technical Consultant

View solution in original post

Abhishek_W
Kilo Guru

Order of execution:

1) onSubmit Client Script runs first (browser / UI)
2) Before Business Rule runs next (server)

Final value saved is value set by the Before Business Rule

Because server-side logic always wins over client-side logic before the record is written to the data

you can also Refer to this image which contains all the script Execution order 

1000018382.png

 

🔴IF you Find this helpful then please give thumbs up👍👍

 

View solution in original post

adityahubli
Tera 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

View solution in original post

SohamTipnis
Giga Guru

Hi @AfifU,

A Client Script runs on the client side and executes based on user actions such as form load, change, or submit. It depends on user interaction and an onSubmit Client Script runs just before the form is submitted to the server.

A Business Rule is a server-side script that runs in the backend and does not depend on user interaction. A Before Business Rule runs before the record is saved to the database, while After and Async rules run later.

Therefore, Client Scripts run first on the client side, and once the request reaches the server, Business Rules execute before the data is committed to the database.

 

If you find my answer helpful, please mark it as Correct and Helpful 😊.

Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant

View solution in original post

Shashank_Jain
Mega 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

View solution in original post

9 REPLIES 9

VaishnaviK43271
Tera Contributor

Hi @AfifU !!

  • Runs first: the onSubmit Client Script

  • Value that is finally saved: the value set by the Before Business Rule

Explanation:

  1. When a user submits the Incident form, the onSubmit Client Script runs in the browser first. Any field values it sets are included in the data sent to the server.

  2. After the data reaches the server, the Before Business Rule runs before the record is written to the database.

  3. If the Business Rule updates the same field, it overwrites whatever value was set by the client script.

Result:
 The Before Business Rule’s value is what gets saved to the record.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for.

Thank You

its_SumitNow
Kilo Sage

replycomm.png

Your Client script is executed first, And then Business rules will run

refer this article:

 https://www.servicenow.com/docs/bundle/zurich-servicenow-platform/page/administer/service-administra...

 

If my response helps, please mark it as helpful and accept as solution

Warm Regards

Sumit Yadav

Technical Consultant

Abhishek_W
Kilo Guru

Order of execution:

1) onSubmit Client Script runs first (browser / UI)
2) Before Business Rule runs next (server)

Final value saved is value set by the Before Business Rule

Because server-side logic always wins over client-side logic before the record is written to the data

you can also Refer to this image which contains all the script Execution order 

1000018382.png

 

🔴IF you Find this helpful then please give thumbs up👍👍

 

adityahubli
Tera 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