help requesting for one onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:07 AM
Hello
I am working on below script
There is Request form.
Configuration item = Reference type
Impact = string type (Yes, No, Null)
when Configuration item = ABC
then donot allow Impact to Yes
for this i have written below script
Onchange Client script (Impact field)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
else{
var ci = g_form.getValue('u_configuration_item').toString();
if(ci == 'ABC'){
g_form.showFieldMsg('u_impact', "The impact should not be set to Yes when Configuration item is ABC", 'error');
}
}
I am not understanding how to check when impact is changing to throw error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:19 AM - edited 12-06-2024 01:21 AM
Hello @Are Kaveri
Try with the below Onchange Client script on Impact field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var ci = g_form.getValue('u_configuration_item').toString();
// Check if the configuration item is 'ABC' and if u_impact is set to 'Yes'
if (ci === 'ABC' && newValue === 'Yes') {
// Show the error message on the u_impact field
g_form.showFieldMsg('u_impact', "The impact should not be set to Yes when Configuration item is ABC", 'error');
} else {
// If the condition is not met, hide any previous error messages on u_impact
g_form.hideFieldMsg('u_impact');
}
}
Please Mark Correct ✔️ if this solves your query and also mark Helpful 👍 if you find my response worthy based on the impact.
Regards,
Shruti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:45 AM
when i tried the below script also not working .
Issue i am facing : getting CI value sys_id instead of display value. checked using alert .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:54 AM
@Are Kaveri, then use getDisplayValue() instead of getValue().
var ci = g_form.getDisplayValue('u_configuration_item');
// Check if the configuration item is 'ABC' and if u_impact is set to 'Yes'
if (ci == 'ABC' && newValue == 'Yes') {
// Show the error message on the u_impact field
g_form.showFieldMsg('u_impact', "The impact should not be set to Yes when Configuration item is ABC", 'error');
}
Please mark my solution as Accepted and Helpful, if it works for you in any way!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 02:02 AM
Hello @Are Kaveri
Please try below within the script:
var ci = g_form.getDisplayValue('u_configuration_item');
Please Mark Correct ✔️ if this solves your query and also mark Helpful 👍 if you find my response worthy based on the impact.
Regards,
Shruti