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: