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

Hii 

Try this ;-

 

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();
 while(gr.next())
 {
 
 usys_id=gr.u_sdm;
 uname=gr.u_sdm.getDisplayValue();

 
 }


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


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

If you need to generate multiple event (1 for each user) then you should put 

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

Inside the while loop and not outside.

while(gr.next())
 {
 
 usys_id=gr.u_sdm;
 uname=gr.u_sdm.getDisplayValue();

 
 }


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

This just overrides usys_id and uname until the last record in the while loop and then sends 1 event.

Try

while(gr.next())
 {
 
 usys_id=gr.u_sdm;
 uname=gr.u_sdm.getDisplayValue();

 gs.eventQueue('inc.50.SDM.event', current, usys_id.toString(), unmae.toString());
 }


In the notification check "send to parm 1"

Hi Simon,

while(gr.next())
 {
 
 usys_id=gr.u_sdm;
 uname=gr.u_sdm.getDisplayValue();

In this section, I have to map the value of the u_team_lead_list field(Glide List) value instead of u_sdm. u_sdm is a reference field which contains only one value.

 

How to pass the U_team_lead_list value ?

 

Regards,

Priya

var leads = gr.u_team_lead_list.toString();  

var usr = new GlideRecord('sys_user'); 

usr.addQuery('sys_id', 'IN', leads.toString()); //This returns all users from the list
usr.query(); 
while(usr.next()){ //This loops through all the members of the u_team_lead_list

 usys_id = usr.getUniqueValue(); //Sys_id of the current team_lead record
 uname = usr.getDisplayValue(); //Display value (name) of the current team_lead record

gs.eventQueue('inc.50.SDM.event', current, usys_id.toString(), unmae.toString());
}   

This should go through all the members of the list, collect names and id's and generate 1 event pr members of the team_lead_list

Hi Simon,

Apologise for the delayed response.

 

I have tried this am able to get the sys id's of the users in the team lead list field. However, in the event log am getting the same persons name everytime while its looping (i.e) if  the list has total 3 persons, am getting 3 entries in event log with the first user name in the list.

find_real_file.png

Regards,

Priya