About

Tuesday, 7 December 2021

Populate caller's name if there's any attachment in Servicenow(SNOW).

 //Display BR


function executeRule(current, previous){

g_scratchpad.email = current.caller_id.email;

g_scratchpad.hasAttachment = current.hasAttachments();

}(current, previous);


//onChange Client Script


function onChange(control, oldValue, newValue, isLoading, isTemplate){

if(isLoading || newValue === ''){

return;

}


if(g_scratchpad.hasAttachment)

alert("Email ID of caller is : "+g_scratchpad.email);

else

alert("NO attachement is in the form");

}

Monday, 29 November 2021

when problem ticket is closed then related incidents should close automatically in Servicenow(SNOW)

We need to create an after business rule in the probelm table with condition and script

/*Sample code*/


var gr = new GlideRecord('incident');

gr.addActiveQuery(); // cross check for only active incidents

gr.addQuery('problem_id',current.sys_id);

gr.query();

while(gr.next()){

gr.state = '6';

gr.close_code = 'Solved(Woek Around)';

gr.close_notes = 'The incident is resolved';

gr.update();

}


gs.addInfoMessage('The incident' +gr.number+ 'is Resolved');

Sunday, 21 November 2021

Reference Qualifier in Advance and Script Include in Servicenow(SNOW).

 On problem form, there should be a field problem owner ans user can only 

select those users in the field who has problem_manager role.


var prbFunctions = Class.create();

prbFunctions.prototype = {

    initialize: function() {},

    getprbmanagers: function() {

        var gr = new GlideRecord('sys_user_has_role');

        gr.addQuery('role', 'b573c1f9538823004247ddeeff7b12e0');

        gr.query();

        while (gr.next()) {

            var prbmanagers = prbmanagers + ',' + gr.user;

        }

        var result = 'sys_idIN' + prbmanagers;

return result;

    },

    type: 'prbFunctions'

};

Tuesday, 16 November 2021

onScript and GlideAjax in Servicenow(SNOW)

 // Script Include


cmdbDetails : function() {

var cmdbid = this.getParameter('sysparm_cmdbid');

var grC = new GlideRecord('cmdb_ci');

grC.addQuery('sys_id', cmdbid);

grC.query();

if(grC.next()){

var cmdbD = "The manufacturer is " + grC.manufacturer.getDisplayValue() +

" and asset tag is " + grC.asset_tag;

}

return cmdbD;

}


//Client Script


function onLoad(){


var ga = new GlideAjax('demoGlideAjax');

ga.addParam('sysparm_name', 'cmdbDetails');

ga.addParam('sysparm_cmdbid', g_form.getValue('cmdb_ci'));

ga.getXML(cmdbCallBack);


function cmdbCallBack(response){

var answer = response.responseXML.documentElement.getAttribute('answer');

alert(answer);

}

}

Sunday, 14 November 2021

caller is VIP onScript function in servicenow

 function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {

      return;

   }

var vipalert = g_form.getReference('u_caller',vipFunction);

function vipFunction(vipAlert){

if(vipAlert.vip == 'true'){

g_form.setValue('priority', '1');

alert('The caller is a VIP person');

}

}

   

}

Saturday, 13 November 2021

Async Await in Javascript(JS)

 Technique 1 for the async await

const pobj1 = new Promise((resolve, reject) => {

    setTimeout(() => {
        let roll_no = [1, 2, 3, 4, 5];
        resolve(roll_no);
    }, 2000);
});

const getBiodata = (indexdata) => {
    return new Promise((resolve, reject) => {
        setTimeout((indexdata) => {
            let biodata = {
                name : 'Vinod',
                age : 26
            }
            resolve(`My name is ${biodata.name} and I am ${biodata.age} years old`);
        }, 2000, indexdata);
    });
}
async function getData(){
    const rollnodata = await pobj1;
    console.log(rollnodata);

    const biodatas = await getBiodata(rollnodata[1]);
    console.log(biodatas);

}
getData();

//Technique 2 for async-await

/*
const pobj1 = new Promise((resolve, reject) => {

    setTimeout(() => {
        let roll_no = [1, 2, 3, 4, 5];
        resolve(roll_no);
    }, 2000);
});

const getBiodata = (indexdata) => {
    return new Promise((resolve, reject) => {
        setTimeout((indexdata) => {
            let biodata = {
                name : 'Vinod',
                age : 26
            }
            resolve(`My name is ${biodata.name} and I am ${biodata.age} years old`);
        }, 2000, indexdata);
    });
}
async function getData(){
    const rollnodata = await pobj1;
    console.log(rollnodata);

    const biodatas = await getBiodata(rollnodata[1]);
    console.log(biodatas);

}
getData();
*/
// New Technique for async await

/*
console.log('person1: shows ticket');
console.log('person2: shows ticket');

const promiseWifeBringTick = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('nunu');
    }, 2000);
})
const getPopcorn = promiseWifeBringTick.then((t) => {
    console.log('husband: we should get in');
    console.log('wife: no I am hungry');
    return new Promise((resolve, reject) => resolve(`${t} popcorn`));
    // console.log(`person3: shows ${t}`);
});

var getButter = getPopcorn.then((t) => {
    console.log('husband: we should go now');
    console.log('wife: I need butter in my popcorn');
    return new Promise((resolve, reject) => resolve(`${t} butter`));
});
getButter.then((t) => console.log(t));

console.log('person4: shows ticket');
console.log('person5: shows ticket');
*/
/*
console.log('This is the new technique');

async function bhaba(){
    console.log("Inside Bhaba function")
    const response = await fetch('https://api.github.com/users');
    console.log('Before Response');
    const users = await response.json();
    return users;
}
console.log("Before calling Bhaba");
let a = bhaba();
console.log('After calling Bhaba');
console.log(a);
a.then(data => console.log(data) )
console.log("This is the last line of the code");
*/

console.log('person1: show ticket');
console.log('person2: show ticket');

const preMovie = async() => {
    const promiseWifeBringTick = new Promise((resolve, reject) => {
        setTimeout(() => resolve('Wife got the Ticket'), 3000);
    });

const getPopcorn = new Promise((resolve, reject) => resolve(`actoo popcorn`));
const getButter = new Promise((resolve, reject) => resolve(`sitajakhala butter`));
    let ticket = await promiseWifeBringTick;

    let popcorn = await getPopcorn;
    console.log(`Husband: I got some ${popcorn}`);
    let butter = await getButter;
    console.log(`Husband: I got some ${butter} as well`);

    return ticket;
}
preMovie().then((m) => console.log(`${m}`));.

Friday, 12 November 2021

Promises in Javascript(JS)

 const pobj = new Promise((resolve, reject)=> {

    setTimeout(()=> {
        let roll_no = [1,2,3,4,6];
        resolve(roll_no);
        // reject("Error while communicating!");
    },2000);
});

const getBiodata = (datas)=>{
    return new Promise((resolve, reject)=> {
        setTimeout(()=> {
            let biodata = {
                name:'vinod',
                age: 23
            }
            resolve(`My roll number is ${datas}. My name is ${biodata.name}. While I
am ${biodata.age} years old.`)
        },2000);
    });
}

// pobj.then((rollno)=> {
//     console.log(rollno);
//     getBiodata(rollno[1]).then((dam)=>{
//         console.log(dam);
//     })
// }).catch((error)=>{
//     console.log(error);
// })

async function getData(){
    const rollnodata = await pobj;
    console.log(rollnodata);

    const biodatas = await getBiodata(rollnodata[1]);
    console.log(biodatas);
}

Monday, 8 November 2021

Basic codes in ServiceNow

 var count = new GlideAggregate('incident');

count.addAggregate('COUNT');

count.query();

var incidents = 0;          

if(count.next()) 

   incidents = count.getAggregate('COUNT');    // we can directly print the count

gs.addInfoMessage(incidents);



gs.addInfoMessage(now_GR.getRowCount());



var count = new GlideAggregate('incident');

count.addQuery('active', 'true');

count.addAggregate('COUNT');

count.query();

var incidents = 0;

if(count.next()) 

   incidents = count.getAggregate('COUNT');

gs.a


----------------------------------------------------


Glide Aggregiate:-


var count = new GlideAggregate('incident');

count.addAggregate('COUNT');

count.query();

var incidents = 0;          

if(count.next()) 

   incidents = count.getAggregate('COUNT');    // we can directly print the count

gs.addInfoMessage(incidents);




gs.addInfoMessage(now_GR.getRowCount());

var count = new GlideAggregate('incident');

count.addQuery('active', 'true');

count.addAggregate('COUNT');

count.query();

var incidents = 0;

if(count.next()) 

   incidents = count.getAggre

var count = new GlideAggregate('incident');

count.addQuery('active','true');

count.addAggregate('COUNT','category');

count.query();

while(count.next()){

  var category = count.category;

  var categoryCount = count.getAggregate('COUNT','category');

  gs.log("there are currently "+ categoryCount +" incidents with a category of "+ category);}


same for glide record try....



var incidentGA = new GlideAggregate('incident');

incidentGA.addAggregate('COUNT');

incidentGA.addAggregate('SUM');

incidentGA

Create email using BR in ServiceNow

    var obj = new GlideRecord('u_practice_on_businessrule');

var f_name = current.u_first_name;

var l_name = current.u_last_name;

current.u_email_2.setValue(f_name+"."+l_name+"@gmail.com");

gs.addInfoMessage("New email Created");

Total record count using GlideRecord in ServiceNow

It can also be executed using glideAggregate 


var inc = new GlideRecord('incident');

//inc.addActiveQuery();

inc.query();

var cat=["inquiry" , "software" , "hardware" , "network" , "database"];

var c1=0, c2=0, c3=0, c4=0, c5=0 , c6=0;

while(inc.next())

{

if(inc.category == cat[0])

{

c1++;

//gs.addInfoMessage(inc.number+" = "+" , "+c1+"  "+cat[0]);

}

else if(inc.category == cat[1])

{

c2++;

//gs.addInfoMessage(inc.number+" = "+" , "+c2+"  "+cat[1]);

}

else if(inc.category == cat[2])

{

c3++;

//gs.addInfoMessage(inc.number+" = "+" , "+c3+"  "+cat[2]);

}

else if(inc.category == cat[3])

{

c4++;

//gs.addInfoMessage(inc.number+" = "+" , "+c4+"  "+cat[3]);

}

else if(inc.category == cat[4])

{

c5++;

//gs.addInfoMessage(inc.number+" = "+" , "+c5+"  "+cat[4]);

}

else if(inc.category == "")

{

c6++;

gs.addInfoMessage(inc.number+" = "+" , "+c6+"  BLANK CATEGORY");

}

}

gs.addInfoMessage("Category = "+cat[0]+" , total number of record = "+c1);

gs.addInfoMessage("Category = "+cat[1]+" , total number of record = "+c2);

gs.addInfoMessage("Category = "+cat[2]+" , total number of record = "+c3);

gs.addInfoMessage("Category = "+cat[3]+" , total number of record = "+c4);

gs.addInfoMessage("Category = "+cat[4]+" , total number of record = "+c5);

gs.addInfoMessage("Category = BLANK CATEGORY , total number of record = "+c6);


gs.addInfoMessage(inc.getRowCount());

Sunday, 7 November 2021

Callback hell in Javascript

 const RollNo = () => {

    setTimeout(() => {
        console.log('Api getting to roll out');
        let roll = [1,2,3,4,6];
        console.log(roll);

        setTimeout( (roll) => {
            const biodata = {
                name : "vinod",
                age : 23
            }
            console.log(`My roll no is ${roll}. My name is ${biodata.name} and my age is ${biodata.age}`);

            setTimeout( () => {
                biodata.gender = "male"
                console.log(`My gender is ${biodata.gender}. My name is ${biodata.name}. While my age is ${biodata.age}. My roll no is ${roll}`);
            }, 2000);

        }, 2000, roll[1]);

    }, 2000);

}
RollNo();