get user_name from List Collector (sys_user) and put user+user_name into hidden variable

Community Alums
Not applicable

I have a catalog item with a list collector that gathers multiple users. When that variable comes through on the ritm/task, it's just a list of names. What is desired is for their user_name to also appear. However, I don't want a separate field on the form that they see when they're filling this out; I only want it to be passed to the ritm/task after the form is submitted. I thought I'd make a multiline textbox variable that could fill in the users and their usernames in this format: 

    Bob User [bob123]
    Sally User [sally456]

by using a client script and script include. Neither is working and when I submit the form, I get 'Unhandled exception in GlideAjax'. Can you please look at what I have and help? 

Here is the client script (ui type=all; applies to cat item, ritm, task): 

function onSubmit() {
   //array of sys_ids from list collector variable 
    var usersToAdd = g_form.getValue('persons_requiring_access').toString().split(',');

    var ga = new GlideAjax('GetListCollectorVariables'); //call the script include
    ga.addParam('sysparm_name', 'UsersListCollector'); //name of function in script include
    ga.addParam('sysparm_users', usersToAdd); //pass array of users to SI
    ga.getXML(GetVariables);

    function GetVariables(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        g_form.setValue('persons_requiring_access_text', answer);
    }
   
}

Here is the script include (client callable = true; global scope) 

var GetListCollectorValues = Class.create();
GetListCollectorValues.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    UsersListCollector: function() {
		var userInfo = '';
		var usersFromListCollector = this.getParameter('sysparm_users');
		var grUser = new GlideRecord('sys_user');
		grUser.addQuery('sys_id','IN',usersFromListCollector);
		grUser.query();
		while(grUser.next()) { 
			userInfo += grUser.name + ' [' + grUser.user_name + ']';
		}
		return info.toString();
    },
    type: 'GetListCollectorValues'
});
1 ACCEPTED SOLUTION

remove this one only glide_list=true

View solution in original post

27 REPLIES 27

See, this is how it will be visible. 

 

find_real_file.png

 

 

Community Alums
Not applicable

This is how the catalog item list collector looks but I don't want the text field visible

find_real_file.png

This is how it comes through on ritm/task (because of read-only client requirement, which doesn't allow the use of a slushbucket). I want that second multiline textbox to be filled with something like this with Name [user.name]: 

    Andrew Och [andrew.o]
    Antony Thierauf [antony.t]
    Annabelle Coger [a.coger]
find_real_file.png

Open that list collector variable, and see if you have added any attribute there? if yes remove it, then it will be appear like slush bucket. 

 

find_real_file.png

 

 

Community Alums
Not applicable

Sadly I cannot remove that, as the client requires the ability to search the list collector and prefers these 2 columns - user_name and name - to appear in the list: 

glide_list=true,ref_ac_columns_search=true,ref_auto_completer=AJAXTableCompleter,ref_ac_columns=user_name;name

remove this one only glide_list=true