How to combine to multiple email scripts on different tables as one email script ?

Community Alums
Not applicable

Hi everyone, 

How can we combine multiple email scripts as one email script for fetching data on email body for different tables.

Scripts:

 var gr = new GlideRecord("cmdb_ci_business_app");
    gr.addQuery('assigned_to.name', event.parm2);
    gr.query();
    while (gr.next()) {
        template.print(gr.number);
        template.print("<br/>");
    }   

 var gr = new GlideRecord("cmdb_ci_service_discovered");
    gr.addQuery('assigned_to.name', event.parm2);
    gr.query();
    while (gr.next()) {
        template.print(gr.number);
        template.print("<br/>");
    }

 

find_real_file.png

Thanks @Ankur Bawiskar , @Mohith Devatte 

1 ACCEPTED SOLUTION

@Venu gopal sr THEN I THINK THIS IS THE ISSUE 

we need to two email scripts in this case 

Reason :

Events and notifications work in such a way that event is on the same table and the notification is on the same table .

So the your notification is on business app table and the event used there is business app so what ever you write in as event.parm1 and event.parm2 it will get  only business app records even if you are glide recording another table and using event.parm2 of its corresponding event it wont catch the value it catches  business app assigned to name only as the notification is on Business app table 

so please have two email scripts in this case 

please mark my answer correct if it helps you and close the thread 

View solution in original post

18 REPLIES 18

Community Alums
Not applicable

on cmdb_ci_business_app @Mohith Devatte 

@Venu gopal sr THEN I THINK THIS IS THE ISSUE 

we need to two email scripts in this case 

Reason :

Events and notifications work in such a way that event is on the same table and the notification is on the same table .

So the your notification is on business app table and the event used there is business app so what ever you write in as event.parm1 and event.parm2 it will get  only business app records even if you are glide recording another table and using event.parm2 of its corresponding event it wont catch the value it catches  business app assigned to name only as the notification is on Business app table 

so please have two email scripts in this case 

please mark my answer correct if it helps you and close the thread 

Community Alums
Not applicable

Hi @Mohith Devatte ,

can you suggest how can we write this code in shorter way for two tables, without having more lines of code.

 

Script:

var bussinessArr = [];
var bussRecipients = [];
var gr = new GlideRecord("cmdb_ci_service_discovered");
gr.addEncodedQuery('assigned_to.active=false^assigned_to.sys_updated_onONLast 7 days@javascript:gs.beginningOfLast7Days()@javascript:gs.endOfLast7Days()');
gr.query();
while (gr.next()) {
    bussRecipients.push(gr.assigned_to.toString());
}
var arrayUtil = new ArrayUtil();
var a1 = arrayUtil.unique(bussRecipients);
for (var i = 0; i <= a1.length; i++) {
    var gr1 = new GlideRecord("sys_user");
    gr1.addQuery("sys_id", a1[i]);
    gr1.setLimit(1);
    gr1.query();
    if (gr1.next()) {
        gs.eventQueue('fa.business.app.accountable.owner', gr1, gr1.manager.email, gr1.name);
    }
}

var bussinessArr1 = [];
var bussRecipients1 = [];
var gr2 = new GlideRecord("cmdb_ci_business_app");
gr2.addEncodedQuery('assigned_to.active=false^assigned_to.sys_updated_onONLast 7 days@javascript:gs.beginningOfLast7Days()@javascript:gs.endOfLast7Days()');
gr2.query();
while (gr2.next()) {
    bussRecipients1.push(gr2.assigned_to.toString());
}
var arrayUtil1 = new ArrayUtil();
var a2 = arrayUtil1.unique(bussRecipients1);
for (var j = 0; j <= a2.length; j++) {
    var gr3 = new GlideRecord("sys_user");
    gr3.addQuery("sys_id", a2[j]);
    gr3.setLimit(1);
    gr3.query();
    if (gr3.next()) {
        gs.eventQueue('fa.business.app.accountable.owner', gr3, gr3.manager.email, gr3.name);
    }
}

 

Thanks
Venugopal S

Community Alums
Not applicable

Hi @Ankur Bawiskar , @Mohith Devatte ,

can you suggest better way for making this script for one notification if the user is same on both tables(cmdb_ci_business_app and cmdb_ci_service_discovered), then email needs to trigger only once, Right now its trigger twice with same data and same user.

scipt:

//Scheduled job for when Accountable owner (user) is inactive on Business Application (cmdb_ci_business_app) table and/or Application Services (cmdb_ci_service_discovered) table then Notification Email needs to send for their manager on every monday 07:00 AM.

validateUser("cmdb_ci_service_discovered");
validateUser("cmdb_ci_business_app");

function validateUser(tableName) {
    var bussinessArr = [];
    var bussRecipients = [];
    var gr = new GlideRecord(tableName);
    gr.addEncodedQuery('assigned_to.active=false^assigned_to.sys_updated_onONLast 7 days@javascript:gs.beginningOfLast7Days()@javascript:gs.endOfLast7Days()');
    gr.query();
    while (gr.next()) {
        bussRecipients.push(gr.assigned_to.toString());
    }
    var arrayUtil = new ArrayUtil();
    var a1 = arrayUtil.unique(bussRecipients);
    for (var i = 0; i <= a1.length; i++) {
        var gr1 = new GlideRecord("sys_user");
        gr1.addQuery("sys_id", a1[i]);
        gr1.setLimit(1);
        gr1.query();
        if (gr1.next()) {
            gs.eventQueue('fa.business.app.accountable.owner', gr1, gr1.manager.email, gr1.name);
        }
    }
}

 

find_real_file.png

 

Thanks

Venugopal S