We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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
Kilo Sage

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 .

 

Not applicable

@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