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

SanjivMeher
Kilo Patron
Kilo Patron

Onload is that user(form_variable_name) already populated?

You should probably use onChange script instead of onLoad.


Please mark this response as correct or helpful if it assisted you with your question.

Yes, the user variable is already populated during onLoad as it is being copied over from an Order Guide. I had put an alert(employee_name) and it gave the sys_id corerctly. 

So basically, there is an order guide containing a reference variable to sys_user and the order guide invokes a catalog item containing the list collector variable. I want the user selected in the order guide to get added to the RHS slush bucket of the list collector of the catalog item. 

I have created a variable with the same name as that of the order guide's variable in the catalog item and it is hidden. So when variable is populated in the order guide it is available in the catalog item as well. I just need to display it in the RHS slush bucket. 

GoBucks
Mega Sage

@dp - Per the Orlando docs on the List collector catalog variable:

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.

Have you checked your data type of employee_name using typeof just to be sure you know what you are getting?

 

Tejas Tamboli
Giga Guru

Hello dp,

You need to set isolate script to false for that onLoad client script; this field is not available on form but from list layout, you can set it to false; by default, it is set to true. Making it to false would allow gel() and DOM manipulation script to work.

 

find_real_file.png

 

 

Mark the answer as Correct/Helpful based on its impact.
 
Thanks,
Tejas