Skip to main content
swapnar6405
April 17, 2023
Solved

multipleDropdownField selection issue

  • April 17, 2023
  • 13 replies
  • 0 views

Hi,

I have a multipleDropdownField with the attached code.

I am getting an error when I try to select any additional item from the dropdown.

Can someone give me an idea how to fix the issue. Thanks in advance.

Using the below code while Testing the user interface.

rule input:

lcmIntakeDesignatedBusinesses:

Best answer by sanchitg0002

Try this:

a!localVariables(
  local!dbkeysFromRi: ri!lcmIntakeDesignatedBusinesses.dbkey,
  local!designatedBusiness: {
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 1, dbname: "Test-1"),
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 2, dbname: "Test-2"),
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 3, dbname: "Test-3"),
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 4, dbname: "Test-4")
  },
  local!selectedDesignatedBusinesses: if(
    a!isNullOrEmpty(ri!lcmIntakeDesignatedBusinesses),
    null(),
    ri!lcmIntakeDesignatedBusinesses.dbkey
  ),
  local!addItems: difference(
    local!selectedDesignatedBusinesses,
    local!dbkeysFromRi
  ),
  local!removeItems: wherecontains(
    difference(
      local!dbkeysFromRi,
      local!selectedDesignatedBusinesses
    ),
    ri!lcmIntakeDesignatedBusinesses.dbkey
  ),
  a!formLayout(
    label: "Form",
    contents: {
      a!sectionLayout(
        contents: {
          a!multipleDropdownField(
            label: "Designated Business/Function",
            labelPosition: "ABOVE",
            helpTooltip: "Designated Business/Function",
            placeholder: "Select a Designated Business/Function",
            choiceLabels: index(local!designatedBusiness, "dbname", ""),
            choiceValues: index(local!designatedBusiness, "dbkey", ""),
            value: local!selectedDesignatedBusinesses,
            saveInto: local!selectedDesignatedBusinesses,
            required: true
          )
        }
      ),
      
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true,
          style: "PRIMARY",
          saveInto: {
            a!forEach(
              local!addItems,
              a!save(
                ri!lcmIntakeDesignatedBusinesses,
                append(
                  ri!lcmIntakeDesignatedBusinesses,
                  'type!{urn:com:appian:types:LCM}LCM_IntakeDesignatedBusiness'(
                    intakedesignatedbusinesskey: null,
                    intakeheaderkey: null,
                    dbkey: fv!item
                  )
                )
              )
            ),
            a!save(
              ri!lcmIntakeDesignatedBusinesses,
              remove(
                ri!lcmIntakeDesignatedBusinesses,
                local!removeItems
              )
            )
          }
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  )
)

I have saved the desired values (addition/removal) in the rule input on Submit button saveInto 

13 replies

April 17, 2023

I see in your a!multipleDropdownField that your value is local!selectedDesignatedBusinesses.dbkey, while the saveInto is local!selectedDesignatedBusinesses. That's not correct, you should save value of the same type. I recommend save the object LCM_IntakeDesignatedBusiness instead of only one field

swapnar6405
April 17, 2023

Hi,

If I re-write saveInto like below, all my previous value are overriding with latest selection.

 ri!lcmIntakeDesignatedBusinesses.dbkey,

harshitb6843
April 18, 2023

Did you check if the above-mentioned field is a multiple type one? 

pragnaj0001
April 17, 2023

Try This. 

a!localVariables(
local!designatedBusiness: {
'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'('dbkey': 1, 'dbname': "Test-1"),
'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'('dbkey': 2, 'dbname': "Test-2"),
'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'('dbkey': 3, 'dbname': "Test-3"),
'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'('dbkey': 4, 'dbname': "Test-4")
},
local!selectedDesignatedBusinesses,
a!formLayout(
label: "Form",
contents: {
a!sectionLayout(
contents: {
a!multipleDropdownField(
label: "Designated Business/Function",
labelPosition: "ABOVE",
helpTooltip: "Designated Business/Function",
placeholder: "Select a Designated Business/Function",
choiceLabels: index(local!designatedBusiness, "dbname", ""),
choiceValues: index(local!designatedBusiness, "dbkey", ""),
value: local!selectedDesignatedBusinesses,
saveInto: {
local!selectedDesignatedBusinesses,

},
required: true
)
}
),

},
buttons: a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Submit",
submit: true,
style: "PRIMARY"
)
},
secondaryButtons: {
a!buttonWidget(
label: "Cancel",
value: true,
saveInto: ri!cancel,
submit: true,
style: "NORMAL",
validate: false
)
}
)
)
)

swapnar6405
April 17, 2023

When the page loads, I will have few values in the below variable 

local!selectedDesignatedBusinesses

I have to be in a position to retain those values in addition to new selections.

April 18, 2023

Try this:

a!localVariables(
  local!dbkeysFromRi: ri!lcmIntakeDesignatedBusinesses.dbkey,
  local!designatedBusiness: {
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 1, dbname: "Test-1"),
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 2, dbname: "Test-2"),
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 3, dbname: "Test-3"),
    'type!{urn:com:appian:types:LCM}LCM_DesignatedBusinesses'(dbkey: 4, dbname: "Test-4")
  },
  local!selectedDesignatedBusinesses: if(
    a!isNullOrEmpty(ri!lcmIntakeDesignatedBusinesses),
    null(),
    ri!lcmIntakeDesignatedBusinesses.dbkey
  ),
  local!addItems: difference(
    local!selectedDesignatedBusinesses,
    local!dbkeysFromRi
  ),
  local!removeItems: wherecontains(
    difference(
      local!dbkeysFromRi,
      local!selectedDesignatedBusinesses
    ),
    ri!lcmIntakeDesignatedBusinesses.dbkey
  ),
  a!formLayout(
    label: "Form",
    contents: {
      a!sectionLayout(
        contents: {
          a!multipleDropdownField(
            label: "Designated Business/Function",
            labelPosition: "ABOVE",
            helpTooltip: "Designated Business/Function",
            placeholder: "Select a Designated Business/Function",
            choiceLabels: index(local!designatedBusiness, "dbname", ""),
            choiceValues: index(local!designatedBusiness, "dbkey", ""),
            value: local!selectedDesignatedBusinesses,
            saveInto: local!selectedDesignatedBusinesses,
            required: true
          )
        }
      ),
      
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true,
          style: "PRIMARY",
          saveInto: {
            a!forEach(
              local!addItems,
              a!save(
                ri!lcmIntakeDesignatedBusinesses,
                append(
                  ri!lcmIntakeDesignatedBusinesses,
                  'type!{urn:com:appian:types:LCM}LCM_IntakeDesignatedBusiness'(
                    intakedesignatedbusinesskey: null,
                    intakeheaderkey: null,
                    dbkey: fv!item
                  )
                )
              )
            ),
            a!save(
              ri!lcmIntakeDesignatedBusinesses,
              remove(
                ri!lcmIntakeDesignatedBusinesses,
                local!removeItems
              )
            )
          }
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  )
)

I have saved the desired values (addition/removal) in the rule input on Submit button saveInto 

jayaprakashr0001
Participating Frequently
April 18, 2023

Hi,

Try to save all the selected values in the localvariables and while submitting the form append the values to the target variable

mikes0011
Brainy
April 18, 2023
append the values to the target variable

this is not really correct advice for this use case.

The Expression Guru
swapnar6405
April 18, 2023

Mike,

Please advise if you are having any other process to handle this case.