Approval script using a reference variable

kmusselle
Kilo Explorer

Hi,

I have a service catalog item called Travel Request Form:

1. There is a variable field that is a reference field to a Table called 'u_budget_holders_and_pas'

2. This table has two fields 'u_budget_holder' and 'u_pa_email'.

I have the script below that should send the approval to the names that are selected in the Table but the approvals are going to the first line entry in the table rather than the one i select, any ideas how to get the approval to send to the name i select and not the first entry, there could be up to 10 people to choose from?

// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.
//
// For example:

var bHolder = current.variables.budget_holder;
var paHolder;


var holderPA = new GlideRecord('u_budget_holders_and_pas');
holderPA.addQuery('user',bHolder);
holderPA.query();
if (holderPA.next()){
  paHolder = holderPA.u_pa_email;

var holderBH = new GlideRecord('u_budget_holders_and_pas');
holderBH.addQuery('user',paHolder);
holderBH.query();
if (holderBH.next()){
  bHolder = holderBH.u_budget_holder;

}
}

answer = [];
answer.push(bHolder);
answer.push(paHolder);
//return answer;

thanks

kathryn

1 ACCEPTED SOLUTION

Hi Kathryn,



If I understand this correctly, your variable is a reference to a custom table you've built with 2 user fields on it, and you want to send an approval to each of the 2 users? If that's the case you can do this a lot simpler just by dot-walking the reference variable like this:



answer = [];


answer.push(current.variables.budget_holder.u_pa_email);


answer.push(current.variables.budget_holder.u_budget_holder);



Please let me know if I've misunderstood your requirements.


View solution in original post

5 REPLIES 5

svizcaino
Kilo Contributor

Hi,



And what if i just want to send one approval?? the field aggrement_user is making reference to the table of sys_user



var agg_user = current.variables.agreement_users.manager;


var count;




var begin = new GlideRecord('u_usd_agreement_telecommute');


begin.addQuery('agreement_users',agg_user);


begin.query();


if (begin.next()){


  count = begin.email;


}


return;