- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2024 03:31 PM
I have a catalog that need to display the class name of the web application based on the selection of a variable called Server. I'm performing an upstream search from the Server CI to retrieve the list of CIs associated with the web component variable, which involves traversing from child to parent. However, I'm currently stuck on how to display the class name of the web application. When I select a server, the web application should show the parent.sys_class_name, such as TOMCAT, APACHE etc. It may consists multiple web applications. If I simply retrieve the class name from the server, it returns Linux Server instead. I can take an alternative approach by selecting the web component first and then displaying the web application, but the customer prefers not to do it this way. If anyone has experienced this issue before, please help me. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2024 12:39 AM
I hope you have the correct choice values and choice labels configured for that web_application variable
I assume your choice value and choice label both are same in that web_application choice variable, if yes then below script will ensure it will add options based on the array returned from script include function
If your choice labels and values are different then you need to use IF else within your script include function and return a JSON object containing choice label and value
Then within client script, parse the json and add the choice labels and choice values.
I hope I have answered your question and you can take it further from here.
if (newValue == '' || newValue == null) {
g_form.setValue('web_application', '');
} else if (newValue != oldValue) {
g_form.setValue('web_application', '');
var ga = new GlideAjax('CLOUAjaxUtils');
ga.addParam('sysparm_name', 'getParentClassName');
ga.addParam('sysparm_childsysid', newValue);
ga.getXMLAnswer(function(response) {
console.log("suraya =:" + response);
var parentClassName = response;
if (parentClassName != '') {
var arr = parentClassName.split(',');
} else {
g_form.clearOptions('web_application'); // Clear the field if no parent class name is found.
}
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2024 06:52 PM
you can use onChange catalog client script + GlideAjax here
what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 09:45 PM
Thank you for the reply. I've applied the onchange client script + GlideAjax, however i got the result in string instead of choices, refer to the ss. The variable type i'm using currently for web applications is single line text.
I created a function that called via client script onchange:
===========================================
====================================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 10:07 PM
return array and not JSON
return arrList.toString();
when you get this array in GlideAjax use g_form.addOption to add the choices to Web component 2 variable
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 10:40 PM
Thank you, but should I use the variable type select box instead of single line text?