If the short description contains INFRA keyword in the beginning then category should add a new choice "infra" and set it to the same by using on change clientscript

Vinod45
Kilo Explorer

Plz send me the script as soon as possible

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As per your question it seems you require onChange client script

sample below

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

var shortDesc = g_form.getValue('short_description');

if(shortDesc.startsWith('INFRA')){

g_form.addOption('choice_field','infra' ,'Infra');

}

else{

g_form.removeOption('choice_field','infra');

}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Vinod 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Vinod,

Minor update to the script to set the value as well.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

var shortDesc = g_form.getValue('short_description');

if(shortDesc.startsWith('INFRA')){

g_form.addOption('choice_field','infra' ,'Infra');
g_form.setValue('choice_field','infra');

}

else{

g_form.removeOption('choice_field','infra');

}

}

zishan khan
Tera Contributor

The query was "

If the short description contains INFRA"

but resolution given was "

If the short description starts with INFRA