- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 11:25 AM
Good afternoon everyone, how are you? I have a variable 'hostname_serial_number'
of type list collector. The user can select more than one value (as expected for this type of variable), and I need to get only the first value through a client script, using g_form.getReference(), so I can then use getValue() to retrieve a specific value ('u_location') from this record. When the user inserts only a single value in the list collector variable, I can get the field using g_form.getReference(), and then retrieve the field value from this record using the getValue() function. However, I’m not able to do this when the user inserts more than one value in the list collector variable. Could you please help me? Thank you very much!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 12:20 PM
Since list collectors store an array of sys_ids as strings, you'd have to getValue of the variable, split on the comma, and then return the first item in the array. You can do this with the below code.
var allSerialNumbers = g_form.getValue('hostname_serial_number'); //or use newValue
// Split the string into an array of sys_ids
var sysIdArray = allSerialNumbers .split(',');
// Access the first element of the array
var firstSysId = sysIdArray[0];
// Log the first sys_id
gs.info("The first sys_id is: " + firstSysId);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 12:20 PM
Since list collectors store an array of sys_ids as strings, you'd have to getValue of the variable, split on the comma, and then return the first item in the array. You can do this with the below code.
var allSerialNumbers = g_form.getValue('hostname_serial_number'); //or use newValue
// Split the string into an array of sys_ids
var sysIdArray = allSerialNumbers .split(',');
// Access the first element of the array
var firstSysId = sysIdArray[0];
// Log the first sys_id
gs.info("The first sys_id is: " + firstSysId);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2025 11:48 AM
Thank you very much!!!