Script not running in native UI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have written an onChange client script on server_name variable which is a list collector variable. This script is working in portal, but not in native UI
In native UI even the alert is not coming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @SHALIKAS ,
Please make sure the following configurations are set in the onChange Client Script:
- UI Type: Select All
- Applies on Requested Items: Checked
- Applies on Catalog Tasks: Checked
This will ensure that the onChange Client Script is applied appropriately when working with both Requested Items and Catalog Tasks in the Native UI.
If you find this response useful, please mark it as Helpful and Accept the Solution.
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Have already marked all the above things
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Just tried your code, try troubleshooting it with g_form.addInfoMessage("Answer = [" + answer + "]") instead of alert("Answer = [" + answer + "]"), from there you can at least see whether you are getting the right values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
53m ago - last edited 52m ago
Hello @SHALIKAS ,
Try this updated script
function onChange(control, oldValue, newValue, isLoading) {
// Stop execution on form initialization or if the field is empty
if (isLoading || !newValue) {
return;
}
// Convert newValue to string to prevent native UI object errors
var valueStr = String(newValue);
if (!valueStr) {
return;
}
// Extract the first Sys ID from the list collector string
var serverList = valueStr.split(',');
var firstServer = serverList[0] ? serverList[0].trim() : '';
if (!firstServer) {
return;
}
// Process the asynchronous GlideAjax request
var ga = new GlideAjax('Coned_fetch_server_details');
ga.addParam('sysparm_name', 'getServerDetails');
ga.addParam('sysparm_sys_id', firstServer);
ga.getXMLAnswer(function(answer) {
if (answer === 'Ansible') {
g_form.setValue('task_for_automation', 'Yes');
} else {
g_form.setValue('task_for_automation', 'No');
}
});
}