Thursday, September 21, 2017

How Client Scripts works in Service Now ?

What is Client Script ?


Client scripts are shipped to 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:

1. Scripts can run on the server, client and browser.
2. As Servers have direct access to database; server scripts are used to generate events.
3. Clients have direct access to forms; client scripts are used to make customization on forms.
4. Types of client scripts:
5. On load - This loads in the background when the form is clicked.
6. On Change: This runs when the user changes the value on the form.
7. On submit: this runs when the user submits the form. Used to validate the values that user added.
8. On celledit scripts: They are like on change. But except they run when the user changes values from the list view drop down.
9. Client scripts control the changes to the form by an API called Glideform.
10. The script calls the glide form API using g_form object.

G_user object is used to provide information about the current user.
G_user methods and properties :
- Makes calls to the database using the server without using the sql. This api uses the gr object.

- GlideAjax APi passes work to the server using scriptinclude.



Best practices of client scripts: 
1. We get a load of client scripts already in the system. So always keep a copy of the original before making any changes to it.
2. Client scripts take a bit time to load the data from server. So, use as less number of get.reference() functions to reduce the load on the server.
3. Write lengthy scripts on server side.
4. Call them using the script include.



Wednesday, September 20, 2017

What is Glide Form ? How it works ?


Glide form is normally use to customize the global applications and template applications which we have in the service now instance .With the use of Glide records we can control the applications form more like delete ,edit ,create ,change etc..

 The validations are done using Client Scripts. g_form is a global object in the Glide Form class. Client Scripts is the best place to excite the G_form objects. With the onload type of client script we can execute the form whenever we load the form. By the on submit type we can submit the form and post the values into the tables .With the on change type we can create a script that we can inter link one field with other field for auto changes .


The methods which we are discussing in the below can make custom changes to the form view of records.

·         G_form.setVisible = this method is use to hide and show the particular field in the form.
·         G_form .setDisplay= There is a little difference in between setVisible and setDisplay .We can maintain the hidden field space with using the setVisible method but with setDisplay we won’t have the space in between the hidden field .
·         G_form.addDecoration = with these we can highlight the particular field with start mark or with popup massage.
·         G_form. Flash = we can highlight the field with color and blinks or flash with particular no of times.
·         G_form.setLablelof =this method is required that user have to be” itill “role, so we can update the project name or whatever the text.
·         G_form.setValue = this method is use to check project status with check marks.
·         G_form.setReadonly =With this method we can make a particular field that will become as read only field, we can’t edit that field .
·         G_form.isnewRecord = to check the record which we are using that new record or old record.

How to display variables on Task Form from Request Item

This is very common and most useful requirement when working with Service Catalog Items.

Out of box, whenever any catalog item is submitted, all the variables will be presented / shown on request item. It will be very difficult for the fulfiller who are working on respective task associated to given request item to see all the variable. fulfiller has to go back to request item and has to come back to task form again.

Requirement : Copy all the variables presented on Request Item form to Task form corresponding to the Request Item.

Implementation :


- Open the catalog item.

- Open the Work flow corresponding to catalog item.

- Open the task where you want to see all the variables.

- Select the variables that you want to see on task form, shuffle to right hand side as shown below.