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

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

Can this be done from a record producer? I'm not having any luck. 😞

I know when setting a traditional reference field at least, that when doing so from the CLIENT side, in order to avoid a round trip back to the server to get the display value field of the referenced record, best practice is to include that third parameter when using setValue. Note how that is different than the 2 parameter g_form.setValue() listed right above it.

Per the 3 parameter version of client-side setValue():

To improve performance by preventing a round trip when setting the value for a reference field, use this method not setValue(fieldName, value). When setting multiple reference values for a list collector field, arrays can be passed in the second and third parameters.

That would imply this IS possible in a list collector variable type without glide_list set to true (despite the not-too-clear doc statements I provided previously regarding "functionality not applicable" when using setValue onLoad.)

I know you mentioned this did not work, but now that you have it working (albeit, with the glide_list attribute set to true) I am curious to know if you simply make this a list collector again (no glide_list attribute, or false) are you able to use setValue() – 3 parameters – successfully?

Note that in our instance this would mean in addition to the sys_id of a user in setValue(), you would also need to get the sys_user.u_name_id field, per the documentation, which is the field on our sys_user table that we have set to display in reference fields. As you know of course, this would be the field that displays the user as: “first_name last_name (user_name)” in all fields that reference sys_user table in our instances.