- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 01:12 AM - edited 02-14-2023 01:14 AM
Hi All,
Hi @Ankur Bawiskar ,
Can anyone please help us on the below issue.
We have two variables.
One is select box type var and other one is List collector [sys_choice table] type var.
Based on the first variable selection we need to populate choices in list collector variable.
we wrote below on change client script on first variable selection level and it's working fine in UI level but when it's comes to portal, it's not working as per the requirement.
Script:
function onChange(control, oldValue, newValue, isLoading) {
var headers = g_form.getControl('roles');
var collectorName = 'roles';
var filterString = '';
if(newValue == 'PO')
{
g_form.clearValue('roles');
filterString = 'nameSTARTSWITHsc_request^element=ABC^dependent_valueSTARTSWITHPO';
}
else if(newValue == 'MM')
{
g_form.clearValue('roles');
filterString = 'nameSTARTSWITHsc_request^element=ABC^dependent_valueSTARTSWITHMM';
}
else if(newValue == 'Citrix')
{
g_form.clearValue('roles');
filterString = 'nameSTARTSWITHsc_request^element=ABC^dependent_valueSTARTSWITHCitrix';
}
else if(newValue == 'Access')
{
g_form.clearValue('roles');
filterString = 'nameSTARTSWITHsc_request^element=ABC^dependent_valueSTARTSWITHAccess';
}
else
{
g_form.clearValue('roles');
}
setCollectorFilter();
function setCollectorFilter()
{
//If it hasn't rendered yet, wait 100ms and try again.
if(typeof(window[collectorName + 'g_filter']) == 'undefined')
{
setTimeout(setCollectorFilter, 50);
return;
}
//Reset the filter query
window[collectorName + 'g_filter'].reset();
window[collectorName + 'g_filter'].setQuery(filterString);
window[collectorName + 'acRequest'](null);
//Redisplay the list collector variable
//g_form.setDisplay(collectorName,true);
}
}
Advance thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 01:40 AM
I have written blog for this and it works in both native + portal
Dynamically set list collector on change of variable
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 01:40 AM
I have written blog for this and it works in both native + portal
Dynamically set list collector on change of variable
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 06:38 AM
Hi Can you please help me with this - I am trying to populate reference field on task_rel_task table from the list collector parent. I am getting error that parent is undefined. Please help.
var answer = [];
var change = current.variables.change_request_number;
var listvalues = current.variables.parent.toString();
var listArr = listvalues.split(',');
for (var i = 0; i < listArr.length; i++) {
var relatedListGR = new GlideRecord('task_rel_task');
relatedListGR.addQuery('child', change);
relatedListGR.query();
while (relatedListGR.next()) {
answer.push(relatedListGR.parent.getDisplayValue().toString());
relatedListGR.setValue('short_description', 'hi');
relatedListGR.setValue('priority', 3);
}
}
gs.info('Answer array is: ' + answer);