About

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