Friday, November 9, 2018

Wednesday, November 7, 2018

How to Extend a Script Include


Script Includes can extend existing Script Includes to access the methods.
In below example, I will demonstrate how we can we extend an existing Script Include with a simple Script Include.
var parentSI = Class.create();
parentSI.prototype = {
    initialize: function() {
    },
 
 upperCase : function(string){
  return string.toUpperCase();
 },

    type: 'parentSI'
};
Below you can see how childSI Script Include extended parentSI
var childSI = Class.create();
//we need to use Object.extendsObject for extending an existing script include
childSI.prototype = Object.extendsObject(parentSI,{
    initialize: function() {
    },
     
 callParent : function(string)
 {
                //calling a method from extended Script Include
  return this.upperCase(string);
 },
    type: 'childSI'
});
var result = new childSI().callParent('servicenow');
gs.log(result);
Output: *** Script: SERVICENOW
Please click here to read more on extending Script Include.
Share:

Tuesday, November 28, 2017

ServiceNow How to get country from Phone Number


We can use this GlideElementPhoneNumber method to get the country from phone number.


var gePN = new GlideElementPhoneNumber();  
// if we have a valid number, parse it 
var valid = gePN.setPhoneNumber("+" + '15406871234', false);
if (valid) {   
var country = gePN.getTerritory();  
gs.log(country);
}

Output: North America

Above code is verified using global scope.

P.S: looks like GlideElementPhoneNumber is undocumented method, I could not find anything on SN docs site.

Share:

Tuesday, November 21, 2017

ServicePortal Server-side Debugging

The server-side GlideSystem class includes methods which can be used for logging/debugging:
  • gs.log() - Global API
  • gs.logError() - Global API
  • gs.logWarning() - Global API
  • gs.warn() - Scoped API
  • gs.info() - Scoped API
  • gs.debug() - Scoped API
  • gs.error() - Scoped API
  • gs.addInfoMessage() - Scoped API and Global API
  • gs.addErrorMessage() - Scoped API and Global API
Happy Debugging 😊
Share:

How to get Changed or Modified Fields in ServiceNow Scoped Apps?

As you know 'GlideScriptRecordUtil' is not allowed in Scoped Apps, we can user below function to get changed fields on server side

//this will give you array of changed field names
var changed _fields = getChangedFieldNames(current);

function getChangedFieldNames(gr) {
 
var result = [];
var elements = gr.getElements();
var size = elements.length;
for (var i = 0; i  < size; i++) {
var ge = elements[i];
if (ge.changes()) {
result.push(ge.getName());
}
}
 
return result;
}

Share: