Error in Multiple Dropdown

Certified Associate Developer

I have used an multiple dropdown box here and whenever i try to select more than 1 option from the multiple dropdown list it is showing this error. Can anyone please guide me through this issue kindly.

Thanks and Regards.

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer
    in reply to yasaswinir216812

    Yes this code is working fine but should i create an rule input every time i want to use a multiple dropdown ? Isnt that gonna make things more complex ?

  • 0
    Certified Associate Developer
    in reply to chaliki



    It is working fine but my doubt here is wether i should create an rule input everytime i have to use a multipledropdown box ?

  • 0
    Certified Lead Developer
    in reply to skzahed_09
    can you please give a brief about what i did wrong and what you did to rectify that error

    As far as I can see, Shubham's answer merely splits the (plaintext, default concatenated) values your multiple dropdown saves (all at once) into the single record value entry, and splits them on the ";" (semicolon character) to create a "value" that's actually an array (which is what the multiple dropdown expects). 

    This (or some other solution) is necessary here because without doing that, the multiple dropdown is expecting to see an array of values but instead just sees a plaintext string consisting of different "benefit" entries cobbled together, and it has no way of knowing which "benefit" entries that cobbled-together string implies.

    I have my own thoughts on storing everything as a cobbled-together string and splitting on semicolon, namely that it relies on Appian's inherent default behavior of joining a text array with semicolon (and a space) when concatenating multiple entries, and this might not always be the same.  Secondly, it means you're storing an arbitrary amount of text entry data all in single fields - which can work, in limited cases, but definitely has weaknesses.

    I would suggest, at the very least, if you want to store a package of multiple entries in a single field of a single record row, wrap that array up in a JSON string first, since JSON is a consistent and predictable format maintained independently of Appian.  It would work similar to the above code example but would avoid using a parsing system quite as arbitrary as splitting on the semicolon character.

  • 0
    Certified Lead Developer
    in reply to skzahed_09

    For example, please consider the following stand-alone approach that replaces the multiple dropdown's behavior that just splits a value on semicolon, with the JSON approach:

    a!localVariables(
      
      local!selection: "",
      /* this will serve as the stand-in for the record field:
      ri!record['recordType!{7d604f1b-53e2-4718-9165-019b6ea8667a}.fields.{0774c72a-97f4-4ec1-a160-b5eaba2af359}']
      */
      
      local!benefits: { "Medical Insurance", "Vision Insurance", "Dental Insurance", "Pension Plan", "Paid Maternity Leave", "Paid Paternity Leave", "Commuter Benifits", "Disability Insurance" },
      
      a!multipleDropdownField(
        choiceLabels: local!benefits,
        choiceValues: local!benefits,
        label: "Benifits",
        labelPosition: "ABOVE",
        placeholder: "--- Select Benefits ---",
        value: a!fromJson(a!defaultValue(local!selection, "[]")),
        /*value: if(
          a!isNullOrEmpty( local!selection ),
          local!selection,
          split( local!selection, "; " )
        ),*/
        saveInto: {
          a!save(
            local!selection,
            a!toJson(save!value)
          )
        },
        searchDisplay: "AUTO",
        required: true,
        validations: {}
      )
    
    )