help requesting for one onchange client script

Are Kaveri
Tera Contributor

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.

9 REPLIES 9

Shruti D
Tera Guru

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

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 .

 

@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

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