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

Help with getting value of variable in multi row variable set instead of sys ID

Bruler1230
Tera Expert

Hello,

I am trying to get the value of a variable that is part of a multi row variable set. I currently am getting the sys id of the variable and cant figure out how to get the actual value. The field in question is the u_user_name field, and it currently only shows the sys id of the variable. here is my script:

var mrvs = JSON.parse(current.variables.user_info);

var user_accounts = '';

var count = 0;

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

if(mrvs[i].u_user_name !=""){
var user = '';
var gr = new GlideRecord('sys_user');
gr.get(mrvs[i].u_user_name);
user += "User Name: " + mrvs[i].u_user_name;
 
}

count++;
var userCount = "User: " + count + '\n';

user_accounts += userCount + '\n' + user + '\n' + "Email: " + mrvs[i].u_email + '\n' + "Phone Number: " + mrvs[i].u_phone_number + '\n' + "Department: " + mrvs[i].u_department + '\n';

}
current.u_user_accounts += user_accounts;
1 ACCEPTED SOLUTION

for option 1;

  • Add a string variable to the variable set. 
  • Add a client script to set the new variable to the user's username.
  • Something like this in the variable set;
  • function onChange(control, oldValue, newValue, isLoading) {
        try {
            g_form.getReference('user', function(userGR){
                g_form.setValue('user_name', userGR.user_name);
            });
        } catch(error) {
            console.log(error);
        }
    }

     

for option 2;

  • Update your script
  • var mrvs = JSON.parse(current.variables.user_info);//array of objects with values
    var returnStr= '';//return string
    for(var i=0; i < mrvs.length; i++); {
      if(mrvs[i].u_user_name !=""){
        var gr = new GlideRecord('sys_user');
        if(gr.get(mrvs[i].u_user_name)){//I assume u_user_name is a ref. to sys_user
          returnStr += "User: " + '\n' + gr.getValue('user_name') + '\n';
          returnStr += "Email: " + mrvs[i].u_email + '\n' 
          returnStr += "Phone Number: " + mrvs[i].u_phone_number + '\n' 
          returnStr += "Department: " + mrvs[i].u_department + '\n';
        }
      }
    }
    current.setValue('u_user_accounts', returnStr);

 

View solution in original post

8 REPLIES 8

Thanks alot for your help and patience through this issue...a little more background on what i am doing just in case it helps. a user is going is use the multi row variable set to input multiple users, all of which need to be displayed on the generated ticket in the u_user_accounts field. I am able to make that work with no problem. Currently, none of the fields variable set are auto populated. The user has to input all info by hand, even the user name. The issue i am facing is that now i am given a requirement that the username field must be a reference field that references the user table. Ideally, i would autopupulate all fields based the user selected, however, at this point, i am not going to worry about that. 

My goal is to get rid of the email field on the variable set form and have them pick the user name from the reference field, which will include the users email. And i will jsut display this on the backend. all other fields can be put in manually at this point. Username and email are most important fields for this application. 

So with all that said, my original script works other than the username showing as a sys id. I just need to get that sys id converted to the user name value for each user that is input. If i can do that and change my current script as little as possible, that would be ideal. But i am open to suggestions. I just need to get this requirement completed and this has become just a little too far out of my abiltiies at this time. Thanks

Try option 2 then.  it's the simplier in terms of executing.

OK...so, i toyed with option 2 and modified it to fit my situation and i was able to get it work after multiple tries. Thank you so much for your help

Thank you option 2 worked...after multiple tries and modifications, i was able to make it work. thanks so much for your help.