Autopopulate List Collector Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 01:25 AM
Morning,
I have a Variable on a Leaver form that displays a specific model of laptop based on the User entered.
The reference qualifier used for this is;
javascript:'assigned_to=' + current.variables.leaver_name+'^display_nameLIKEdell INC. lat';
This is working as intended however I would like to make it so that the list is automatically populated and does not require the assets to be selected from the listing.
Does this require an on Change Catalog Client Script or is there another way of completing this?
Thanks in advance,
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 01:43 AM
Hi @jack ashman
Yes, you can achieve the functionality by changing the reference field with the list collector field. Just pass the sys_ids of the records you want to display.
Please hit helpful if this resolves your query.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 01:56 AM
Thanks @_Gaurav ,
Sorry if I am misunderstanding, I'm relatively new at this;
I have the variable as a List Collector as follows but it still requires the user to select the assets from the listing rather then auto-filling the list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 02:01 AM - edited 01-19-2024 02:05 AM
@jack ashman
Do not use the reference qualifier if you want to auto-populate the data, you need to write an OnChange client script.
From the script include passing the sys_ids to the CS then by using g_form.setValue you can set the value in the list collector field.
For ref:
https://www.servicenow.com/community/in-other-news/portal-diaries-setting-list-collector-values-in-s...
Also please hit helpful if this resolve your query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 02:38 AM
Hi @jack ashman
You can try my script below to get the Leaver Assets and auto-populate them to a list collector.
#Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue('leaver_assets'); //your variable name
}
var ga = new GlideAjax('CLCatalogItemUtilAJAX');
ga.addParam('sysparm_name', 'getLeaverAssets');
ga.addParam('sysparm_leaver_id', newValue); //assume leaver_name is a reference field to table User
ga.getXMLAnswer(function(answer){
g_form.setValue('leaver_assets', answer); //your variable name
});
}
#Script Include (Make sure the Client Callable checkbox is checked)
var CLCatalogItemUtilAJAX = Class.create();
CLCatalogItemUtilAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLeaverAssets: function(){
var leaverID = this.getParameter('sysparm_leaver_id');
var hardwareDisplayName = 'dell INC. lat';
var hardwares = [];
var grHardware = new GlideRecord('alm_hardware');
grHardware.addQuery('assigned_to', leaverID);
grHardware.addQuery('display_name', 'LIKE', hardwareDisplayName);
grHardware.query();
while(grHardware.next()){
hardwares.push(grHardware.getUniqueValue());
}
return hardwares.join(',');
},
type: 'CLCatalogItemUtilAJAX'
});
Cheers,
Tai Vu