Please help with setting List Collector Default Value based on other text field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 10:37 AM
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.
Here is my currently configure, but this did not work. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 11:13 AM
Hi @Jessica28 ,
Hope you are doing great.
to set the default value of a List Collector field based on another text field in ServiceNow.
Navigate to the form where you want to implement this functionality (e.g., the IT asset management form).
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.
Edit the form and go to the client script section.
Create a new client script and set its type to "onLoad."
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;
}
}
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:50 PM
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: