List Collector's right slush bucket is not populating with onLoad Client script

dp11
Tera Guru

Using an onLoad client script, I want to auto-populate the right slush bucket of a List Collector type variable with a value from left slush bucket on a catalog form. A solution was provided and accepted in the post below.  I am using  g_form.setValue('list name', sys_id) as suggested...but t does not work for me. Any idea what could be wrong?

https://community.servicenow.com/community?id=community_question&sys_id=8825ac27dba6089414d6fb243996...

 

function onLoad() {

var employee_name = g_form.getValue('form_variable_name referencing sys_user');
if (employee_name != ""){
   g_form.setValue('list_name referencing sys_user', employee_name);
}

BTW, the employee does exist in the left slush bucket.

Thanks!

16 REPLIES 16

it was false already by default, perhaps

The SN Nerd
Giga Sage
Giga Sage

I think you need to set the display value as well:

function onLoad() {

var employee_name = g_form.getValue('form_variable_name referencing sys_user');
var employee_display = g_form.getDisplayBox('form_variable_name referencing sys_user').value;
if (employee_name != ""){
   g_form.setValue('list_name referencing sys_user', employee_name, employee_display  );
}

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

this did not work either

What part didn't work?

Can you add a log statement?

var employee_name = g_form.getValue('form_variable_name referencing sys_user');
var employee_display = g_form.getDisplayBox('form_variable_name referencing sys_user').value;
// Check that we are getting the display value
jslog("employee_display: " + employee_display );
if (employee_name != ""){
   g_form.setValue('list_name referencing sys_user', employee_name, employee_display  );
}

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Many thanks for the follow up, Paul. I added the log statement and it correctly logged the value for employee_display. I believe there is some issue for onLoad client script with a List-Collector variable type. It states in the docs below:

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/product/service-catalog-management/reference/r_VariableTypes.html#d233535e663

"When the glide_list attribute is not true, you can only set the value that is visible in the Available list using the g_form.setValue() function. This functionality is not applicable when the setValue() function is called onLoad."

So, I have now moved on to setting the attribute "glide_list" for the variable and things are working.