Virtual Agent: Getting the user selection for "Reference Choice List" user input?

huntj06
Tera Guru

I'm populating a reference choice which is outputting the options to the end user:

Name   |    Value

End Chat       end_chat

Live Agent    live_agent

The list shows up fine, but I need to find out what the user selection is so I can use my decision tree accordingly. 

You can see in my two attachments how the activity is setup.I'm logging the following:find_real_file.png

You can see I selected the "End Chat" option in the window, but it's logging the last entry when I do 

var selection = vaInputs.chat_action_ref.getValue();
gs.info("Chat Action selection: " + selection);

How can I get/store the option the user has chosen? 

4 REPLIES 4

Adrian22
Kilo Explorer

Hi huntj06,

I had a similar problem. I needed the value of user input to send it over through REST method. In my case, I get always the first value.

You need to assign the value in separate script action block and it`s better to use global value. So try to add "Script Action" right after the "Reference choice" (as showed on below screen).

find_real_file.png

 

Before that add script variable (in this example "options").

In "Script action" code assign user input from "Reference choice" to this variable:

vaVars.options = vaInputs.chat_action_ref; //I`m not using getValue(), it`s working without it

Correct user input should be in "vaVars.options". After that, you can use it later in the code.
I hope that will work for you too.

Regards.

 

Good Afternoon,

 

Nice little tip but do you know how to return the sys_id instead? if I use "getDisplayValue();" then it returns the name of the person, if I don't use anything then I get nothing at all.

i.e. 

vaVars.options = vaInputs.list_employees; //Returns Nothing
user = vaInputs.list_employees.getDisplayValue(); //Returns the name of the person selected, also problematic if your showing more than just the name field using:
 
var options = [];
var gr = newGlideRecord(table);
gr.addQuery('name','CONTAINS',vaInputs.employee_name);
gr.setLimit(15);
gr.query();
while(gr.next()) {
options.push({ 'value': gr.getValue('name') + " - " + gr.getValue('email')});
}
return options;
 
 

All I am doing is a user search to log a request, a list of names display, they click on the correct name and then I am trying to use that when creating a new Request to populate the Requested For field.

Wondering if I need to push the sys_id into the array as well but don't want that displayed in the list shown.

Any suggestions and I would be grateful

Kind Regards

Ashley

Not to worry, figured it out in the end

Kind Regards

Ashley

Adalberto
Kilo Explorer

Try

var selection = vaInputs.chat_action_ref.getValue('sys_id');