How to send emails to multiple persons using workflow run script activity and gs.event queue.

gspriya
Kilo Expert

 I have a requirement to send email notifications to a list of people configured in our custom form when the SLA configured exceeds 50%. This is achieved via workflow Run Script activity. 

 I have a field called Team Lead List which is a Glide List field in our custom form Location Based Assignments. 

 Now I need to send the emails to all the members in the team lead list field when sla exceeds 50%.   My script is as follows: 

 try

var arrayEmail = [];

var incLocation=current.task.location;

var incSupportGrp=current.task.assignment_group;

var usys_id=gs.getProperty('corporate.office.SDM.sysID'); 

var uname=gs.getProperty('corporate.office.SDM.name'); 

 var gr=new GlideRecord('u_location_based_assignment'); 

gr.addQuery('u_location',incLocation); 

gr.addQuery('u_support_group',incSupportGrp); 

gr.query(); 

if(gr.next()) 

var arrayUtil = new ArrayUtil(); 

var leads = gr.u_team_lead_list.toString(); 

var arrayList =leads.split(","); 

temp = arrayList.length; 

//gs.print("Array Value: " + temp);  /

//gs.print("Array.length:" + temp.length);   

for(i=0;i<temp;i++)  {     

var usr = new GlideRecord('sys_user'); 

usr.addQuery('sys_id', 'IN', arrayList[i]);  usr.query(); 

while(usr.next()){ 

arrayEmail.push(usr.getValue[i]('email')); 

}   

 gs.eventQueue('inc.50.SDM.event',current,arrayList.toString());   

}

}

catch(e)

gs.log('in side catch:'+e,'w123'); }       But when I execute it I am not getting the sysid's of the user instead it setting some value like 'Created on <time>'   Please tell me how to fix this       

Regards,   

Priya        

1 ACCEPTED SOLUTION

Okay, great.

Could you mark my answer as correct/helpful if this helps.

View solution in original post

23 REPLIES 23

Hi Kalai,

 

I have tried replacing the entire query block with the single gs.event queue statement. But am getting blank values in param 1 field in event log.

Actually am trying to pass sysid's of all members in the team lead list(glide list) field in order to notify them. If no value exists in team lead list field I will default it to corporate SDM value using gs.get property.

Currently am using the below script where I am sending only 1 value as team lead value and its working fine,

 

try
{

var incLocation=current.task.location;
var incSupportGrp=current.task.assignment_group;

var usys_id=gs.getProperty('corporate.office.SDM.sysID');
var uname=gs.getProperty('corporate.office.SDM.name');

var gr=new GlideRecord('u_location_based_assignment');
gr.addQuery('u_location',incLocation);
gr.addQuery('u_support_group',incSupportGrp);
gr.query();
if(gr.next())
{

usys_id=gr.u_sdm;
uname=gr.u_sdm.getDisplayValue();

}

gs.eventQueue('inc.50.SDM.event',current,usys_id,uname);

}
catch(e)
{
gs.log('in side catch:'+e,'w123');
}

 

How to modify this script to send  emails to all members in team lead list field

 

Regards,

Priya

I was suggesting to try this.

if(gr.next())
{

gs.eventQueue('inc.50.SDM.event',current,gr.u_team_lead_list.toString());   

}

 

Hi

 

I tried this, but am not getting any values in the param field in event log.

Regards,

Priya

Is the fieldname correct? Is teamlead a reference field? Have you tried to log the values from teamlead field?

gspriya
Kilo Expert

Hi,

Actually am trying to pass sysid's of all members in the team lead list(glide list) field in order to notify them. If no value exists in team lead list field I will default it to corporate SDM value using gs.get property.

Currently am using the below script where I am sending only 1 value as team lead value and its working fine,

 

try
{

var incLocation=current.task.location;
var incSupportGrp=current.task.assignment_group;

var usys_id=gs.getProperty('corporate.office.SDM.sysID');
var uname=gs.getProperty('corporate.office.SDM.name');

var gr=new GlideRecord('u_location_based_assignment');
gr.addQuery('u_location',incLocation);
gr.addQuery('u_support_group',incSupportGrp);
gr.query();
if(gr.next())
{

usys_id=gr.u_sdm;
uname=gr.u_sdm.getDisplayValue();

}

gs.eventQueue('inc.50.SDM.event',current,usys_id,uname);

}
catch(e)
{
gs.log('in side catch:'+e,'w123');
}

 

How to modify this script to send  emails to all members in team lead list field

 

Regards,

Priya