Using an IF statement with a multi-select field in an OnChange Script

SOLVED

Hi Everybody,

I hope someone can help me understand how to use an IF statement with a Multi-Select field in an OnChange script.

This basic IF statement can determine whether Blue has been selected in a Text or Selection field.

if (oppo_color.value == 'Blue')

However, it doesn't work with a Multi-Select field, which is what I really need.

Is there something I can do to make that work?

Thanks very much in advance!

Kevin

Parents
  • +1
    verified answer

    The value of the field is an array (as multiple options can be selected). Sticking with the example of oppo_color, if we want to see if 'Blue' is included in the selected options then this will do it:

    if(crm.fields('oppo_color').val().includes('Blue')) {
    
       //do whatever..
    
    }

    If we're only interested when 'Blue' has been selected exclusively then this will work:

    var v = crm.fields('oppo_color').val();
    if(v.length === 1 && v.includes('Blue')){
    
    }

Reply
  • +1
    verified answer

    The value of the field is an array (as multiple options can be selected). Sticking with the example of oppo_color, if we want to see if 'Blue' is included in the selected options then this will do it:

    if(crm.fields('oppo_color').val().includes('Blue')) {
    
       //do whatever..
    
    }

    If we're only interested when 'Blue' has been selected exclusively then this will work:

    var v = crm.fields('oppo_color').val();
    if(v.length === 1 && v.includes('Blue')){
    
    }

Children