Adding the watch list to an array

Dubz
Mega Sage

Morning All,

We have a script running on our change form that is used to send notifications to all customers that have a service offering that is dependent on the CI on the change.

I've included the script below, it is basically pulling out all the customers and getting rid of duplicates and then acquiring all their service offerings and presenting these as parm1 and parm2 respectively.

I want to add in the watch list to the list of recipients in parm1 but i don't know how to add them to the array. I've tried various permutations along the lines of

var custArray = firstArray.push(current.watch_list);

and

var combArray = new ArrayUtil();

var firstArray = combArray.concat(custArray, current.watch_list);

and even

var newArray = new ArrayUtil();

var watchArray = newArray.convertArray(current.watch_list);

var combArray = new ArrayUtil();

var firstArray = combArray.concat(customers, watchArray);

Please help me!!

(function executeRule(current, previous /*null when async*/) {

var customers;

var count = 0;

//get all affected service offerings

var gr = new GlideRecord("task_cmdb_ci_service");

gr.addQuery("task", current.sys_id);

gr.query();

while (gr.next()) {

//get all affected customers

if(count == 0){

customers += gr.u_company;

}

else {

customers += "," + gr.u_company;

}

count++;

}

//remove duplicate customers

var custArray = customers.split(",");

var arrayUtil = new ArrayUtil();

var uniqueCustArray = arrayUtil.unique(custArray);

//trigger notification to all affected customers

for (var i=0; i<uniqueCustArray.length; i++) {

var serviceOfferings = "";

var emailAddress = "";

var count1 = 0;

//get all service offerings for affected customer

var gr1 = new GlideRecord("task_cmdb_ci_service");

gr1.addQuery("task", current.sys_id);

gr1.addQuery("u_company", uniqueCustArray[i]);

gr1.query();

while (gr1.next()) {

if(count1 == 0){

serviceOfferings += gr1.cmdb_ci_service.u_service_id;

}

else {

serviceOfferings += ", " + gr1.cmdb_ci_service.u_service_id;

}

count1++;

}

//get email addresses of affected customers

var gr2 = new GlideRecord("core_company");

if (gr2.get(uniqueCustArray[i])) {

emailAddress = gr2.u_primary_contact;

}

//trigger event

gs.eventQueue("change.customer.notification.reminder", current, emailAddress, serviceOfferings);

}

})(current, previous);

6 REPLIES 6

Hi,

here when i am using gs.print(arr);

its showing the watch list users, but i want to get their first names 

how can i get it.

for ex: Abel Tutor and Abraham Lincoln are watchlist users

i want their firstname - Abel and Abraham.

var arr = [];
//var fName = [];
var inc=new GlideRecord('u_create_new');
inc.addQuery('number','ENRL0187');
inc.query();
if(inc.next())
{
arr.push(inc.watch_list.split(','));
//fName.push(arr.getFirstName.split(','));
//gs.print(fName);

gs.print(arr);
}

Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi David,



Try with below code.



var arrayUtil = new ArrayUtil();


var array1= [];


var array2= [];


vr array3=[];


array3=arrayUtil.concat(array1, array2);



Hope this helps.



Regards


Ujjawal