Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to autopopulate choice if there is single value

Community Alums
Not applicable

Hi Team,

 

We have a requirement wherein if we select subcategory in case form, there is a a choice field called "Customer Requested", which should autopopulate  if there is a single value based on the Sub category and should not be maually selected.

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage

Hi @Community Alums ,

 

You need to create a onChange client script

onChange variable - subcategory

Client script: please double check the backend name of the variable and change accordingly

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

    var custReq = g_form.getElement('u_customer_requested');

    if (custReq.options.length == 1) {

        g_form.setValue('u_customer_requested', custReq.options[0].value);

    }
}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

  

View solution in original post

1 REPLY 1

Karan Chhabra6
Mega Sage

Hi @Community Alums ,

 

You need to create a onChange client script

onChange variable - subcategory

Client script: please double check the backend name of the variable and change accordingly

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

    var custReq = g_form.getElement('u_customer_requested');

    if (custReq.options.length == 1) {

        g_form.setValue('u_customer_requested', custReq.options[0].value);

    }
}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!