Autopopulate Select box variable based on string variable

JRY
Mega Guru

Hello All,

 

I'm trying to populate a selectbox variable based on a single line text field. As we can see in the below image, I'm trying to autopopulate dropdown choice based on a single line text field value. As you can see in the below image, but below script, it's not working as expected. Can someone help me with corrections to the script?

 

LAN ID == Single line Text variable

Domain == Dropdown/selectbo

JRY_0-1666710521861.png

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var lanId = g_form.getValue('lan_id');
    lanId = ["ACCPT", "AF", "AP", "EA", "NA", "SA", "UPSTREAMACCTS"];
    if (lanId.indexOf('ACCPT') !== -1) {
        g_form.setValue('domain', 'ACCPT');
    } else if (lanId.indexOf('AF') !== -1) {
        g_form.setValue('domain', 'AF');
    } else if (lanId.indexOf('AP') !== -1) {
        g_form.setValue('domain', 'AP');
    } else if (lanId.indexOf('EA') !== -1) {
        g_form.setValue('domain', 'EA');
    } else if (lanId.indexOf('NA') !== -1) {
        g_form.setValue('domain', 'NA');
    } else if (lanId.indexOf('SA') !== -1) {
        g_form.setValue('domain', 'SA');
    } else if (lanId.indexOf('UPSTREAMACCTS') !== -1) {
        g_form.setValue('domain', 'UPSTREAMACCTS');
    }


}

 

Thanks,

JRY

 

 

 

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hi @JRY 

Can you try this:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var lanId = g_form.getValue('lan_id');
    //lanId = ["ACCPT", "AF", "AP", "EA", "NA", "SA", "UPSTREAMACCTS"]; //commented this line
    if (lanId.indexOf('ACCPT') >-1) {
        g_form.setValue('domain', 'ACCPT');
    } else if (lanId.indexOf('AF') >-1) {
        g_form.setValue('domain', 'AF');
    } else if (lanId.indexOf('AP') >-1) {
        g_form.setValue('domain', 'AP');
    } else if (lanId.indexOf('EA')>-1) {
        g_form.setValue('domain', 'EA');
    } else if (lanId.indexOf('NA') >-1) {
        g_form.setValue('domain', 'NA');
    } else if (lanId.indexOf('SA') >-1) {
        g_form.setValue('domain', 'SA');
    } else if (lanId.indexOf('UPSTREAMACCTS') >-1) {
        g_form.setValue('domain', 'UPSTREAMACCTS');
    }


}

 

Hope it works

 

Thanks,
Murthy

View solution in original post

10 REPLIES 10

Hello,

 

Can you elaborate a little that what is your use case? Like do you want to show the options as dropdown? But I see for every option you are setting only one dropdown so why not just make it a string field and populate it.

 

If you could elaborate  a little it would be easier to help.