- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 06:08 AM
I have created a Script Include and catalog client script on the Requested for field. But when I remove the requested for files value the remaining field values of location, city etc are not cleared and remaining the same.
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 11:01 AM
Hi @GBS
It seems like the issue is that the Catalog Onchange Client script is only triggered when the requested_for field is changed to a non-empty value. When the requested_for field is cleared, the script is not triggered and therefore the remaining fields are not cleared.
To fix this, you can add an additional check in the Catalog Onchange Client script to see if the requested_for field is empty. If it is empty, you can manually clear the remaining fields using the g_form.setValue() method.
Here's an updated version of the Catalog Onchange Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
// Clear remaining fields
g_form.setValue('req_manager', '');
g_form.setValue('city', '');
g_form.setValue('state', '');
return;
}
var ga = new GlideAjax('VertivUser');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(answer) {
if (answer != 'not found') {
var parser = JSON.parse(answer);
g_form.setValue('req_manager', parser.u_reference_1);
g_form.setValue('city', parser.u_city);
g_form.setValue('state', parser.state);
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 11:01 AM
Hi @GBS
It seems like the issue is that the Catalog Onchange Client script is only triggered when the requested_for field is changed to a non-empty value. When the requested_for field is cleared, the script is not triggered and therefore the remaining fields are not cleared.
To fix this, you can add an additional check in the Catalog Onchange Client script to see if the requested_for field is empty. If it is empty, you can manually clear the remaining fields using the g_form.setValue() method.
Here's an updated version of the Catalog Onchange Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
// Clear remaining fields
g_form.setValue('req_manager', '');
g_form.setValue('city', '');
g_form.setValue('state', '');
return;
}
var ga = new GlideAjax('VertivUser');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(answer) {
if (answer != 'not found') {
var parser = JSON.parse(answer);
g_form.setValue('req_manager', parser.u_reference_1);
g_form.setValue('city', parser.u_city);
g_form.setValue('state', parser.state);
}
});
}