About

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);
}