- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 12:00 AM
Hi,
I want to show the list collector value in select box. How to do that? Right now I have a script include which is fetching the value of a list field. I want to show that values in a select box in the catalog item.
Please help in this.
Thanks!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 06:25 AM - edited 03-21-2023 06:29 AM
Hi @Samiksha2 ,
Try changing your client script to the one below.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var ga = new GlideAjax('getUsername');
ga.addParam('sysparm_name', 'getUser');
ga.addParam('request_for', newValue);
ga.getXMLAnswer(setProduct);
function setProduct(response) {
var resp = JSON.parse(response);
for(var i=0; i < resp.length; i++){
g_form.addOption('u_hardware', resp[i], resp[i]);
}
}
}
Note: Check if the Script Include is Client Callable and returning the values needed.
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 05:14 AM - edited 03-21-2023 05:14 AM
Hi @Samiksha2 ,
I understand that, you want the values of a list collector field values as options in select box drop down, is that correct?
If Yes, what is the table the list collector field is referring to? And, are you using just the SelectBox in catalog form or that one is also referring to same table as List collector?
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 05:36 AM - edited 03-21-2023 05:37 AM
Hi @AnveshKumar M,
Here the requirement is in u_hardware table there are three fields- Primary(reference) and Backup(List) field and name(String). In the catalog Item- there are three varibles- Requested for(logged in User), Select the Option and Hardware(Select box).
scenario is - If requested for is Primary and Backup then the respective hardware name will populate in the Hardware field.
When a requester is a primary or backup of multiple hardware products then both product name should display in the drop down.
Script Include
getUser: function() {
var userSys = [];
var requested_for = this.getParameter('request_for');
var hardware_val = new GlideRecord("u_hardware");
hardware_val.addQuery('u_primary=' + requested_for + '^ORu_backupLIKE' + requested_for);
hardware_val.query();
while (hardware_val.next()) {
userSys.push(hardware_val.getValue('name'));
}
return JSON.stringify(userSys);
},
Client script:(onChnage of Requested for)
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var ga = new GlideAjax('getUsername');
ga.addParam('sysparm_name', 'getUser');
ga.addParam('request_for', newValue);
ga.getXML(setProduct);
function setProduct(response) {
var ans = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
g_form.setValue('u_hardware', ans);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 06:25 AM - edited 03-21-2023 06:29 AM
Hi @Samiksha2 ,
Try changing your client script to the one below.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var ga = new GlideAjax('getUsername');
ga.addParam('sysparm_name', 'getUser');
ga.addParam('request_for', newValue);
ga.getXMLAnswer(setProduct);
function setProduct(response) {
var resp = JSON.parse(response);
for(var i=0; i < resp.length; i++){
g_form.addOption('u_hardware', resp[i], resp[i]);
}
}
}
Note: Check if the Script Include is Client Callable and returning the values needed.
Thanks,
Anvesh
Anvesh