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 02:06 AM
Hi @Are Kaveri ,
var ci = g_form.getDisplayBox('u_configuration_item').value;
Above line will work.
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:23 AM
Hello @Are Kaveri,
Please refer to the code below and use it in an onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getValue('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 01:30 AM
Hello @Are Kaveri
- Write an onchange client script on impact field.
onChange Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || isTemplate) {
return;
}
// Get the values of the Configuration Item and Impact fields
var ci = g_form.getValue('u_configuration_item'); // Reference field value
var impact = g_form.getValue('u_impact'); // String field value
// Check if the Configuration Item is "ABC" and Impact is set to "Yes"
if (ci === 'ABC' && impact === 'Yes') {
// Display an error message
g_form.showFieldMsg('u_impact', "The impact should not be set to Yes when Configuration item is ABC", 'error');
// Clear the Impact field value
g_form.setValue('u_impact', '');
}
}
After implementing this script, the Impact field will automatically display an error message and prevent the value from being set to "Yes" when the Configuration Item is "ABC."
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:40 AM
Hello @Are Kaveri,
You can follow the below script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getValue('u_configuration_item');
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');
return false;
} else {
return true;
}
}
Please mark my solution as accepted and give thumbs up, if it helps you.
Regards,
Abhishek Thakur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:54 AM - edited 12-06-2024 02:00 AM
Hi @Are Kaveri ,
var ci=g_form.getDisplayBox("u_configuration_item").value;
//as this field is reference field you will get sys_id, sys_id=ABC will not enter into if loop, so use getDisplayBOX to get string value.
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand