Can client scripts be used for both lists and forms?

rakesh52
Kilo Contributor

Can client scripts be used for both lists and forms?

7 REPLIES 7

Alikutty A
Tera Sage

Hello,

Client scripts are mainly for forms and there is one type which is specific to lists ie oncell edit. All the other 3 types for clients scripts ie onLoad, onChange and onSubmit are for the forms?

Also if you need to add validations on a list view, you should be using a business rule.

Types of client scripts

Thanks!

onLoad() â€” runs when the system first renders the form and before users can enter data. Typically, onLoad() client scripts perform client-side-manipulation of the current form or set default record values.

onSubmit() â€” runs when a form is submitted. Typically, onSubmit() scripts validate things on the form and ensure that the submission makes sense. An onSubmit() client script can cancel form submission by returning a value of false.

onChange() â€” runs when a particular field value changes on the form. The onChange() client script must specify these parameters.
  • control: the DHTML widget whose value changed.
  • oldValue: the value the widget had when the record was loaded.
  • newValue: the value the widget has after the change.
  • isLoading: identifies whether the change occurs as part of a form load.
  • isTemplate: identifies whether the change occurs as part of a template load.
onCellEdit() â€” runs when the list editor changes a cell value. The onCellEdit()client script must specify these parameters.
  • sysIDs: an array of the sys_ids for all items being edited.
  • table: the table of the items being edited.
  • oldValues: the old values of the cells being edited.
  • newValue: the new value for the cells being edited.
  • callback: a callback that continues the execution of any other related cell edit scripts. If true is passed as a parameter, the other scripts are executed or the change is committed if there are no more scripts. If false is passed as a parameter, any further scripts are not executed and the change is not committed.

Hello Rakesh,

Is this answered? Do you have any other queries. If your query is answered, please do mark the correct answer and close the thread.

 

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi rakesh,

With the exception of onCellEdit() client scripts, client scripts only apply to forms and search pages. If you create a client script to control field values on a form, you must use one of these other methods to control field values when on a list.

  • Create an access control to restrict who can edit field values.
  • Create a business rule to validate content.
  • Create a data policy to validate content.
  • Create an onCellEdit() client script to validate content.
  • Disable list editing for the table.

For any other information, please refer to the official documentation:

Client scripts

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto