Wednesday, March 28, 2018

Query a reference field ; ServiceNow

In the below table(discovery_range_item_ip) item_parent is a reference field;


var range_table=new GlideRecord('discovery_range_item_ip');
range_table.addQuery('item_parent.name', "JDC_AIX1_RANGE");
range_table.query();
gs.log('Row Count'+ range_table.getRowCount());

Code base #2

-- item table
AIX1 Y
AIX2 Y
AIX3 N

----
Excel -->values-->insert into AIX3-->{code to check total count --Full set isFull to Yes}---> create new table AIX4 -->isFull --"No"---
Start inserting --->count reaches 250----> isFull='Yes'----

Code Base #1

var res = 500/250;
    if(res%1!=0){
    res=Math.ceil(res);
    }
    else{
    res=res+1;
    }

Saturday, March 24, 2018

Javascript to split ; ServiceNow Script

var str = "172.168.1.1";
var res = str.split(".", 2);
gs.log(res);

https://www.w3schools.com/jsref/jsref_split.asp


Insert Row to a Glide Record table ServiceNow

//Create a new Incident record and populate the fields with the values below
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'Network problem';
gr.category = 'software';
gr.caller_id.setDisplayValue('Joe Employee');
gr.insert();


Reference: https://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/


Friday, March 23, 2018

Custom VIP icon ServiceNow

Create an image in image module
get the name of the image (Example: VIP.gif)
Go to Caller Field->Configure styles->style->

background-image: url('VIP.png');
background-repeat: no-repeat;
background-position: center center;
padding-right: 30px;





Go to Client Scripts-> Highlight VIP Caller->change the URL to updated one

before :

callerLabel.setStyle({backgroundImage: "url('images/icons/vip.gif')", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});


after:

callerLabel.setStyle({backgroundImage: "url('VIP.png')", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});




Image Picker ServiceNow


Example:
https://dev21517.service-now.com/image_picker.do

https://<instance>/image_picker.do

image_picker



Thursday, March 22, 2018

Get union of 2 arrays removing intersection values (Javascript)


var array1 = ['12','1','10','19','100','test'];
var array2 = ['12','10','19','test1'];
var array3 = array1.filter(function(obj) { return array2.indexOf(obj) == -1; });
var array4 = array2.filter(function(obj) { return array1.indexOf(obj) == -1; });
gs.print('----> array1 Values----->'+  array1);
gs.print('----> array2 Values----->'+  array2);
gs.print('----> array3 Values----->'+  array3);
gs.print('----> Concat Values----->'+  array3.concat(array4));








Reference:
https://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items


Scheduled Script ServiceNow (Navigation)













Discovery troubleshooting | Error messages

  Discovery troubleshooting | Error messages - Support and Troubleshooting (servicenow.com) Description Learn how to resolve common Discover...