Please help with setting List Collector Default Value based on other text field

Jessica28
Tera Guru

Hello,

Could someone please help on setting List Collector Default Value based on other text field?

When form load, we need the populate the List Collector with the value in Current Manger field.

 

Jessica28_0-1690565563542.png

 

Here is my currently configure, but this did not work.  Thank you

 

Jessica28_1-1690565762217.png

 

2 REPLIES 2

Riya Verma
Kilo Sage
Kilo Sage

Hi @Jessica28 ,

 

Hope you are doing great.

 

to set the default value of a List Collector field based on another text field in ServiceNow.

  1. Navigate to the form where you want to implement this functionality (e.g., the IT asset management form).

  2. Identify the field code of the List Collector field and the Current Manager text field. You can find these codes by inspecting the HTML elements of the form or by going to the form design view in ServiceNow.

  3. Edit the form and go to the client script section.

  4. Create a new client script and set its type to "onLoad."

  5. Write the JavaScript code to retrieve the value from the Current Manager field and populate it in the List Collector field. Replace "list_collector_field_code" and "current_manager_field_code" with the actual field codes from step 2.

Reference script :

 

function onLoad() {
 
  var currentManagerValue = g_form.getValue('current_manager_field_code');

  var listCollectorField = g_form.getControl('list_collector_field_code');

  if (currentManagerValue) {
    var defaultValueArray = [];
    defaultValueArray.push(currentManagerValue);
    listCollectorField.options = defaultValueArray;
  }
}

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Thank you for helping @Riya Verma 

I forgot to mention in the thread those are variable fields.

I must have done some wrong in order to make it not working.

Here is the screenshot:

 

Jessica28_0-1690573796992.png