The CreatorCon Call for Content is officially open! Get started here.

How can I script an email recipient based on the value of a variable

Cupcake
Mega Guru

I have a catalog item that has a variable (select box) that contains a list of names. In addition, I have an email notification baked inside of the workflow. What I am trying to do is send the email notification to person that is selected in that select box. Is this something that can be accomplished?

find_real_file.png

 

find_real_file.png

 

1 ACCEPTED SOLUTION

guruprasad1
Kilo Guru

Hi

 

Can try this

answer = [];

answer.push(current.variable.variable_name);

Regards

Guru

View solution in original post

16 REPLIES 16

Good day to you,

     I am just now getting back to this. The select box is not a reference field.

Is there a way to do this without it being a reference field?

 

Thanks,

Karen

Hi Karen,

 

Yes you can still do this with just the name but you're going to have to use that name to glide into the user table and retrieve the sys_id because that's what you need to pass to the workflow activity. Have a go with the script below and confirm what is in the gs.logs. You should get an array of names (firstname+lastname) and then and array of sys_id's.

answer = [];  
var arrAppr = current.variables.u_approver.split(",");
gs.log('this is the array: ' + arrAppr);
for (var i = 0; i < arrAppr.length; i++) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name', arrAppr[i]);
gr.query();
while(gr.next()){
answer.push.(gr.getValue('sys_id'));
}
gs.log('this is the answer: ' + answer);

cheers

Dave

Hi David,

     I figured it out. I just needed to change the field to a reference field only showing those users and then the script below did the trick.

answer = [];


answer.push(current.variables.variable_name.sys_id);

 

Thank you for responding so quickly.

Have a great weekend.

Karen

Glad you got it working, have a good one šŸ™‚

add a gs.log to see what the value of your arrAppr is returning. If it's already a list of sys_id's you might not even need the for loop. If you do need the loop you'll need to get rid of the rogue colon in there

answer = [];  
var arrAppr = current.variables.u_approver.split(",");
for (var i = 0; i < arrAppr.length; i++) {
    answer.push.(arrAppr[i].toString());

}