- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 09:29 PM - edited 01-02-2024 08:50 AM
Hi all,
How to auto populate or auto select value in list type field when there is only one choice/ record available for selection?
Thank You!
RK.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 08:49 PM
Hi @Rutuja K
From your screenshot above, you can try the below approach.
1. Create an OnChange Client Script in the Product ID [u_product_id] field.
2. Make a GlideAjax call with the same query to the gethostingtype function. Then return an array contains the sys_id of Hosting Type records.
3. Now in Client Script, check if the array length in response and set the value to the Hosting Type.
Sample below.
#Script Include
getServices: function() {
var owner = this.getParameter('sysparm_owner_id');
var arrService = [];
var grService = new GlideRecord('cmdb_ci_service');
grService.addQuery('owned_by', owner);
grService.query();
while (grService.next()) {
arrService.push(grService.getUniqueValue());
}
return JSON.stringify(arrService);
},
#OnChange Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue('business_services');
}
var ga = new GlideAjax('CLCatalogItemUtilAJAX');
ga.addParam('sysparm_name', 'getServices');
ga.addParam('sysparm_owner_id', newValue);
ga.getXMLAnswer(function(answer) {
var service = JSON.parse(answer);
if (service.length === 1) {
g_form.setValue('business_services', service[0]);
return;
}
g_form.clearValue('business_services');
});
}
Enjoy
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 09:46 PM
Hi,
You can provide a default value directly for any choice you want to show as auto select
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 09:55 PM - edited 01-01-2024 09:55 PM
Thanks for responding Adarsh,
I didn't understand what you are suggesting
can you please explain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 10:22 PM
auto-populate but based on what criteria?
please explain your business requirement in detail along with screenshots.
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 10:28 PM - edited 01-01-2024 10:28 PM
Hi @Ankur Bawiskar ,
based on value selected in one field, I want to populate value in list type field.
List collector records are fetched from another table. If there is only one record available for selection then I want that to-be populated by default.
