The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference between client script and business rule

sruthivarghese
Tera Contributor

Hi,

What is the difference between client script and business rule apart from the one that client script runs on the form and business rules on the database. Suppose I have a business rule which prints a message when one field in the form is empty and I have a client script that does the same thing. How do I come to know whether it is the Business rule or the client script that worked.

Thanks in advance

Sruthi

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Sruthi,



If the message is displayed during form load or on change of any field then it is a client-side operation or can be a Display BR. However, if the message is shown after the form is submitted then it can be onSubmit client script or business rule.


Srvs
Kilo Guru

Hi Sruthi,



client script executed on client browser, it included onload, onsubmit, onchange, oncellEdit.



Business rule is server side scripting used to perform the operation on server, its having the types 1)before 2) after


executed at the time of 1) display or query 2) insert 3) update 4)delete



@serch with wiki on more, if you need any help ask me



Regards


Venkat


Rajashekhar M
Kilo Sage
Kilo Sage

Hello Sruthi,



I hope this helpful to you,



The major difference between of them client script always runs on clisnt side browser and Business Rule always runs on server side when a record inserted/updated/deleted/queried   from data base.



Client-based code:


"Client-based code that executes in the browser, using Ajax or running as Javascript, always executes before the form submission to the server."


This includes Client scripts and UI Policies.



First onLoad Client scripts, after that the first UI Policies kick in.


After that, the Client scripts and UI Policies that work onChange.


After that, the Client scripts that work onSubmit.



Server-side code: (More info: Execution Order of Scripts and Engines)


  1. Before business rules:
  2. Before engines.
  3. Before business rules:
  4. The data base operation (insert, update, delete).
  5. After business rules:
  6. After engines.
  7. Email notifications.
  8. After business rules.



Similarities

Same3.png



Most scripts have a name and specify a table.


1.2 Important Differences

The most important differences among scripts are


  • the function of the script (what it is used for) and
  • whether the script runs on the client or server.

1.3 Client vs. Server

The web browser is the client, and is often the only software that is installed at the customer site.The application server and the database are located at the data center.


  • Client scripts run on the client (which is the web browser)
  • Server scripts run on the server (which includes the application server and the database)

The web browser is where you control and communicate with an instance, including communicating with the server and database.


NoteNote: When you are writing scripts, you cannot use reserved words.

Scripts - Their Functions and Where They Run

Choose the module name for further information.


ScriptFunctionRuns on
http://wiki.servicenow.com/index.php?title=Using_Access_Control_Rules
Business RulesCustomizes system behavior
  • runs when a database action occurs (query, insert, update or delete)
  • the script may run
  • before or after the database action is performed (runs as part of the database operation)
  • asynchronously (at some point after the database operation)
  • on display (when displaying the data in a form)
server - script and any condition run on the server
Client ScriptsUsed for making changes to the appearance of forms, displaying different fields based on values that are entered or other custom display options.
  • onLoad means the Client Script runs when the form or page is loaded
  • onChange means the Client Script runs when something specific gets changed AND also when the form or page loads
  • onSubmit means the Client Script runs when the form is submitted
Client Scripts can also be called by other scripts or modules, including UI Policies.
client




Thanks,
Rajashekhar Mushke
Rising star -2023 & 2022
Community Leader -2018

Rajashekhar M
Kilo Sage
Kilo Sage

now coming to your questions,



business rule which prints a message when one field in the form is empty and I have a client script that does the same thing. How do I come to know whether it is the Business rule or the client script that worked.



Ans : The server side query or display business rule runs first.   That is during load of the record from the server side.   Then client side scripts will pick up. Then, before and after business rules.




Thanks,
Rajashekhar Mushke
Rising star -2023 & 2022
Community Leader -2018