• Call us: +91 9501707741
  • tutorialzdiary@gmail.com

ServiceNOW

ServiceNOW Training

ServiceNow Training Course
ServiceNOW Admin Training Course
ServiceNOW Development Training Course

ServiceNOW Hands on

ServiceNOW : How to get personal ServiceNOW instance to start exploring
ServiceNOW : List & Forms Administration
ServiceNOW : Reporting Module
ServiceNOW : Scheduling and Publishing Reports
ServiceNOW : Scripts & APIs
ServiceNOW : Workflows
ServiceNOW : Service Catalog Module
ServiceNOW : Incident Management
ServiceNOW : Change Management
ServiceNOW : Configuration Management
ServiceNOW: Business Rules & basic functions
ServiceNOW: Business Rule- Sample Scripts
ServiceNOW: Client Script-Sample Scripts
ServiceNOW : Knowledge Management
ServiceNOW: Client Script & basic functions
ServiceNOW : Changes in Incident,Change & Service Catalog Module in Helsinki(latest version of ServiceNOW)
ServiceNOW : Reference Qualifier

ServiceNOW Interview Questions and Answers

Part 2: USER ADMINISTRATION & ESS
Part 1 : CMDB
Part 3: SLA
Part 4 : Scripts
Part 5: Table & Data Dictionary
Part 6: ACL
Part 7: Workflow
Part 8: Service Catalog

ServiceNOW: Client Script & basic functions

Client scripts are used in the client (the browser) and run there instead of on the server. Users who know JavaScript can define scripts to run in the client browser. Several types of scripts are supported:

There are 4 types of client side code :

  1. OnLoad() : The system loads a form
  2. OnChange() :
    • The system loads a form loads and no field values have changed
    • A field value changes

  3. OnSubmit() : A user saves the form
  4. OnCellEdit() : A list cell value changes

 

types of client script

types of client script

OnLoad() script:

An onLoad() script runs when a form is first drawn and before control is given to the user to begin typing. Typically, you use an onLoad() script to perform some client side manipulation of the document on screen.

An onLoad() script must contain a function named onLoad(). Otherwise, it is entirely up to you what your script does after it gets to the client.

OnSubmit() script :

An onSubmit() script runs when a form is submitted. Typically, you use an onSubmit() script to validate things on the form and ensure that the submission makes sense. As such, onSubmit() scripts can potentially cancel a submission by returning false.

An onSubmit() script must contain a function named onSubmit().

OnChange() script:

An onChange() script can run when a particular field changes value or when the form is first drawn and no fields have changed value from previous script actions. As such, onChange scripts can potentially act as onLoad scripts with extra conditions.

An onChange() script must contain a function named onChange().

All onChange() scripts are called with several parameters:

  • control – the field whose value changed if any.
  • oldValue – the value of this widget when the record was loaded into the form.
  • newValue – the value of this widget after the change, or when the isLoading parameter is true, the same value as the oldValue parameter.
  • isLoading – identifies whether the form is loading and also indicates that no fields have changed value. This parameter can only be true when the form is loading and no values have changed.
  • isTemplate – identifies whether the change occurs as part of a template load or not.

 
OnCellEdit() script :

Scripts can be defined as onCellEdit to run on the client side when the list editor interacts with a cell.
 
An onCellEdit() script must contain a function named onCellEdit().

An onCellEdit() script takes the following 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.

 
HOW TO CREATE NEW CLIENT SCRIPT

Step 1: Go-to CLIENT SCRIPT module & click on NEW button, this will open a page:

Client Script

Client Script


 
Step 2: Fill in all the details & script as per your requirement & click on SAVE/SUBMIT.

BASIC FUNCTIONS USED IN CLIENT SIDE CODES

  1. getActionName() : Returns the most recent action name or, for a client script, the sys_id of the UI Action clicked. Note: not available to Wizard Client Scripts.
  2. getFormElement() : Returns the HTML element for the form.
  3. getSectionNames() : Returns all section names, whether visible or not, in an array.
  4. getSections() : Returns the elements for the form’s sections in an array.
  5. getTableName() : Returns the name of the table this record belongs to.
  6. getUniqueValue() : Returns the sys_id of the record displayed in the form.
  7. isNewRecord() : Returns true if the record has never been saved. Returns false if the record has been saved.
  8. isSectionVisible(sectionName) : Returns true if the section is visible. Returns false if the section is not visible or does not exist.
  9. addErrorMessage(message) : Displays an error message at the top of the form.
  10. addInfoMessage(message) : Displays an informational message at the top of the form.
  11. clearMessages() : Removes messages that were previously added with addErrorMessage() and addInfoMessage().
  12. enableAttachments() : Allows new file attachments to be added. Shows the paperclip icon.
  13. disableAttachments() : Prevents new file attachments from being added. Hides the paperclip icon.
  14. save() : Saves the record without navigating away from the record (update and stay).
  15. setSectionDisplay(sectionName, display) : Shows or hides a section. Works in both tab and flat modes.
  16. submit() : Saves the record. User will be taken away from the form, returning them to where they were previously.
  17. addOption(fieldName, choiceValue, choiceLabel, [choiceIndex]) : Adds a choice to a choice list field. If the index is not specified, the choice is added to the end of the list.Optional: Use the index field to specify a particular place in the list.
  18. clearOptions(fieldName) : Removes all options from a choice list.
  19. removeOption(fieldName, choiceValue) : Removes a specific option from a choice list.
  20. clearValue(fieldName) : Removes any value(s) from the specified field.
  21. setDisabled(fieldName, boolean) : Grays out field and makes it unavailable.
  22. setMandatory(fieldName, boolean) : Makes the field required if true. Makes the field optional if false.Best Practice: Use UI Policy rather than this method whenever possible.
  23. setReadOnly(fieldName, boolean) : Makes the field read-only if true. Makes the field editable if false. Note: Both setReadOnly and setReadonly are functional. Best Practice: Use UI Policy rather than this method whenever possible.
  24. setValue(fieldName, value, displayValue) : Sets the value and the display value of a field. Will display value if there is no displayValue. To improve performance by preventing a round trip, include a display value in addition to the value.Note: setValue can cause a stack overflow when used in an OnChange client script. This is because every time the value is set, it will register as a change, which may re-trigger the OnChange client script. To prevent this, perform a check that will validate that the new value will be different from the old value. For example, before performing setValue(fieldName, newValue.toUpperCase());, validate that the short description is not already uppercase. This will prevent the Client Script from applying the toUpperCase() more than once.
  25. isMandatory(fieldName) : Returns true if the field is required. Returns false if the field is optional.
  26. getValue(fieldName) : Returns the value of the specified field.
  27. getDecimalValue(fieldName) : Returns the decimal value of the specified field.
  28. getReference(fieldName, callback) : Returns the GlideRecord for a specified field. getReference() accepts a second parameter, a callback function.
  29. getOption(fieldName, choiceValue) : Returns the <option> element for a select box named fieldName and where choiceValue matches the option value.Returns null if the field is not found or the option is not found.
  30. getIntValue(fieldName) : Returns the value of the specified field as an integer. An empty value returns 0.
  31. getElement(id) : Returns the HTML element for the field specified via the ID. Compound fields may contain several HTML elements. Generally not necessary as there are built-in methods that use the fields on the form.
  32. getControl(fieldName) : Returns the HTML element for the specified field. Compound fields may contain several HTML elements.Generally not necessary as there are built-in methods that use the fields on the form.
  33. getBooleanValue(fieldName) : Returns false if the field’s value is false or undefined, otherwise true is returned.Useful with checkbox fields. Returns true when the checkbox is checked.
  34. addDecoration(fieldName, icon, title) : Adds an icon on a field’s label.
  35. flash(widgetName, color, count) : Flashes the specified color the specified number of times. Used to draw attention to a particular field.
  36. getLabelOf(fieldname) : Gets the plain text value of the field label.
  37. hideAllFieldMsgs([type]) : Hides all field messages. Optional: Provide type to clear only “info” or “error” messages.
  38. hideErrorBox(input) : Hides the error message placed by showErrorBox(). Best Practice: Use hideFieldMsg rather than this method whenever possible.
  39. hideFieldMsg(input, [clearAll]) : Hides the message placed by showFieldMsg().
  40. hideRelatedList(listTableName) : Hides the specified related list on the form.
  41. hideRelatedLists() : Hides all related lists on the form.
  42. removeDecoration(fieldName, icon, title) : Removes the icon that matches the exact same name and text.
  43. setDisplay(fieldName, boolean) : Displays the field if true. Hides the field if false. If the field is hidden, the space is reclaimed. Best Practice: Use UI Policy rather than this method whenever possible.
  44. setLabelOf(fieldname, label) : Sets the plain text value of the field label.
  45. setVisible(fieldName, boolean) : Displays the field if true. Hides the field if false. If the field is hidden, the space is left blank. Best Practice: Use UI Policy rather than this method whenever possible.
  46. showErrorBox(input, message, [scrollForm]) : Displays an error message under the specified form field (either a control object or the name of the field). If the control or field is currently scrolled off the screen, it will be scrolled to. Optional: Set scrollForm to false to prevent scrolling to the error message offscreen.
  47. showFieldMsg(input, message, type, [scrollForm]) : Displays either an informational or error message under the specified form field (either a control object or the name of the field). Type may be either “info” or “error.” If the control or field is currently scrolled off the screen, it will be scrolled to.Optional: Set scrollForm to false to prevent scrolling to the field message offscreen.
  48. showRelatedList(listTableName) : Displays the specified related list on the form.
  49. showRelatedLists() : Displays all related lists on the form.

 

image_pdfimage_print

Leave a reply

Your email address will not be published. Required fields are marked *


Newsletter
Training Enquiry