SCRIPTING IN SERVICE NOW

CLIENT SCRIPT

1. G-FORM:GlideForm.js is the Javascript class used to customize forms.

g_form.getValue(‘short_description’)
g_form.setValue(‘short_description’, “”)
g_form.addOption(‘priority’, ‘2.5’, ‘2.5 – Moderately High’, 3)
g_form.getTableName()
g_form.addErrorMessage(‘This is an error’)
g_form.addInfoMessage(‘The top five fields in this form are mandatory’)
g_form.showFieldMsg(‘impact’,’Low impact response time can be one week’,’info’)
g_form.showFieldMsg(‘impact’,’Low impact not allowed with High priority’,’error’)
g_form.flash(“incident.number”, “#FFFACD”, 0)

2. g_user: g_user is a global object in GlideUser, can only used in Client Script contains name and role information about the current user.
g_user.userName
g_user.userID
g_user.firstName
g_user.getClientData(“loginlanguage”)
g_user.hasRole(‘admin’)
g_user.hasRoleExactly(‘util’)
g_user.hasRoleFromList(“itil, maint”)
g_user.hasRoles()

3. GlideAjax:We can call server script from client script using glideajax.

  1. var Temp = Class.create();
    Temp.prototype = Object.extendsObject(AbstractAjaxProcessor, {
     
         helloWorld: function() {
          return “Hello ” + this.getParameter(‘sysparm_user_name’) + “!”+this.getParameter(‘sysparm_pass’);
       },
        
        type: ‘Temp’
    });
     
     
    function onLoad() {
      
         var ga = new GlideAjax(‘Temp’);
           ga.addParam(‘sysparm_name’,’helloWorld’);
           ga.addParam(‘sysparm_user_name’,”Bob”);
         ga.addParam(‘sysparm_pass’,”ppp”);
        
           ga.getXML(HelloWorldParse);
     
    function HelloWorldParse(response) {
       var answer = response.responseXML.documentElement.getAttribute(“answer”);
       alert(answer);
    }
     } 

Server Side Script

1. GlideRecord API:

var gr=new GlideRecord(“incident”);

gr.addQuery(“number”,”INC00001″)

gr.query();

while(gr.next()){

gr.short_description=”this comment need to update”;

gr.update();

}

var gr=new GlideRecord(“incident”);

GlideRecord is used for database operations.

gr is an object of  GlideRecord API, so we can access all the fields of gliderecord table.

gr.addQuery():- adds a filter condition for return records or you can say it will add the filter condition while quering the database for glide record table.

gr.query:- Query the database with addQuery conditions.

while(gr.next()){

NEXT: iteration of gliderecord object. It moves to next record .

gr.short_description=”this comment need to update”;

gr.update();

update: it will update record with the above assigned field values.

}

……………………………………………………………………………..

var rec = new GlideRecord(‘incident’);
rec.addQuery(‘active’,false);
rec.query();
while (rec.next()) {
 gs.print(‘Inactive incident ‘ + rec.number + ‘ deleted’);
gr.setDisplayValue(‘field_name’,’value’);
gr.insert()
gr.update();
 rec.deleteRecord();
}

2. Glidesystem:- used to get information about system,user session data —not used in custom scoped app

  1. current: used for read/write operation in business rules
  2. previous:used for read operation in business rules.

gs.eventQueue(“incident.commented”, current, gs.getUserID(), gs.getUserName())
gs.getProperty(‘glide.servlet.uri’)
gs.log(“temp”);
gs.addErrorMessage(“Error Message “)
gs.addInfoMessage(‘start must be before end’);

 

About the author

Leave a Reply