saving dropdown

if(
  ri!taskCode = cons!IC_TEXT_TASKCODE_RESERVE_NO_FOREWARD,
  {
    a!columnsLayout(
      columns: {
        a!columnLayout(
          contents: {
            a!dropdownField(
              label: "Pull Zone",
              value: local!pullZoneValues,
              choiceLabels: local!pullZoneList,
              choiceValues: local!pullZoneList,
              placeholderLabel: "Select a Value",
              saveInto: {a!save(local!pullZoneValues,save!value),
              a!save(
                local!getLocnId,
                rule!IC_QRY_getLocnidFromMSTLocationHeader(local!pullZoneValues)
              ) }

            )
          }
        ),

        a!columnLayout(
          contents: {
            a!dropdownField(
              label: "Location ID",
              value:if(
                isnull(local!pullZone),
                null,
                index(ri!selectedTask,"locnId",null)
              ), 
            
              choiceLabels: union(local!getLocnId,local!getLocnId),
              choiceValues:union(local!getLocnId,local!getLocnId),
              disabled: isnull(local!pullZoneValues),
              placeholderLabel : "Select a Value",
              saveInto: a!save(
                ri!selectedTask.locnId,
                save!value
              )


            )
          }
        )
      }
    )

  },
  {}
),

/* rule!IC_QRY_getLocnidFromMSTLocationHeader */

a!queryEntity(
  entity: cons!IC_ENTITY_MST_LOCATION_HEADER,
  query: a!query(
    selection: a!querySelection(
      columns: {
        a!queryColumn(
         
          field: "locnId"
        )
      }
    ),
    logicalexpression: a!queryLogicalExpression(
      operator: "AND",
      filters: {
      
        a!queryFilter(
          field: "SKUId",
          operator: "is null"
        ),
          
          
        a!queryFilter(
          field: "pullZone",
          operator: "=",
          value: ri!pullZone
        )
      }
    ),
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: - 1,
      sort: {}
    )
  )
).data.locnId

the second dropdown field is not saving the values, whenever I select a value in dropdown it disappears. Any help would be appreciated.

  Discussion posts and replies are publicly visible

  • I cleared and edited like you said and tried to select the values from pull zone again. when I select the pull zone and pick a location ID. You can see that the value is stored in rule input for the location ID. But in the column field it disappears. 

  • 0
    Certified Lead Developer
    in reply to Siddharth Thiagarajan

    I notice you've re-added the if() statement here for some reason -- so we're back to the original problem that your "isnull()" statement is checking the value of local!pullZone, which (at least in your earlier code example) never gets assigned a value.  I think you may have meant to put local!pullZoneValues in that isnull(), because otherwise the second dropdown will never display any value.

  • If I just use index. on the very fist user interaction, im able to select the pull zone and location ID but on the next instance if i try to select a different pull zone, I started to get an error. In order to avoid that error I used the if condition.

  • 0
    Certified Lead Developer
    in reply to Siddharth Thiagarajan

    So that's a different issue altogether - to handle that, you need to add a new save into the saveInto of the first dropdown, to save a blank value into the value of the second dropdown anytime it's changed.  This is a fairly standard requirement when developing cascading dropdowns where the selections in one depend on the value chosen in a previous one.

  • if(
          ri!taskCode = cons!IC_TEXT_TASKCODE_RESERVE_NO_FOREWARD,
          {
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!dropdownField(
                      label: "Pull Zone",
                      value: local!pullZoneValues,
                      choiceLabels: local!pullZoneList,
                      choiceValues: local!pullZoneList,
                      placeholderLabel: "Select a Value",
                      saveInto: {
                      a!save(local!pullZoneValues,save!value),
                      a!save(
                        local!getLocnId,
                        rule!IC_QRY_getLocnidFromMSTLocationHeader(local!pullZoneValues)
                      ) }
                        
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!dropdownField(
                      label: "Location ID",
                      value:index(ri!selectedTask,"locnId",null),     
                      choiceLabels: union(local!getLocnId,local!getLocnId),
                      choiceValues:union(local!getLocnId,local!getLocnId),
                      disabled: isnull(local!pullZoneValues),
                      placeholderLabel : "Select a Value",
                      saveInto:a!save(
                        ri!selectedTask.locnId,
                        save!value
                      )
                     
                     
                    )
                  }
                )
              }
            )
    
          },
          {}
        )

    This is the current status of the code. It would be really grateful if you modify saveinto and show on the first drop down

  • 0
    Certified Lead Developer
    in reply to Siddharth Thiagarajan

    Try this.  BTW i think for the "value" of the second dropdown we can just directly access the ri property, as it likely won't have the issue of the property not existing (rule inputs are typecast to their CDT type, so the property will exist whether it's null or not).

    if(
      ri!taskCode = cons!IC_TEXT_TASKCODE_RESERVE_NO_FOREWARD,
      {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: "Pull Zone",
                  value: local!pullZoneValues,
                  choiceLabels: local!pullZoneList,
                  choiceValues: local!pullZoneList,
                  placeholderLabel: "Select a Value",
                  saveInto: {
                    a!save(local!pullZoneValues, save!value),
                    a!save(
                      local!getLocnId,
                      rule!IC_QRY_getLocnidFromMSTLocationHeader(local!pullZoneValues)
                    ),
                    a!save(
                      ri!selectedTask.locnId,
                      null()
                    )
                  }
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: "Location ID",
                  value: /* property(ri!selectedTask, "locnId", null), */ ri!selectedTask.locnId,
                  choiceLabels: union(local!getLocnId, local!getLocnId),
                  choiceValues: union(local!getLocnId, local!getLocnId),
                  disabled: isnull(local!pullZoneValues),
                  placeholderLabel : "Select a Value",
                  saveInto:a!save(
                    ri!selectedTask.locnId,
                    save!value
                  )
                )
              }
            )
          }
        )
      },
      {}
    )

    (but, the important change I made is this:

    )

  • What is the data type of ri!selectedTask?  If it's not type cast to a CDT, then you will probably need to change the "value" line back to how you originally had it (the commented out portion of the code I last posted).

  • 0
    Certified Lead Developer

    Perhaps for the sake of simplicity, we take a step back, and you simply try to implement a cascading dropdown with nothing else in a separate rule.

    Create a test interface on your dev environment. (I find a very good practice is for all developers to have their own test folders for trying out things in Appian)

    Try making a dropdown with 2 choices, "One" and "Two"

    Try making another dropdown that either shows "One point One" and "One point Two" OR "Two point One" and "Two point Two", depending on the value of the top dropdown.  Also, think about what you want the bottom dropdown to do when you haven't selected anything in the top dropdown.

    Save the result of the top dropdown to an ri! and the result of the bottom dropdown to another ri!

    When you get that working, apply what you've learned to the far more complex problem you have before you.

    Good practice when you have anything troubling you to boil down whatever you're trying to accomplish as far down as you can boil it.  This limits the possible sources of errors until you can get the simplest version working.  Then gradually add complexity back, checking often to make sure it still works.

  • 0
    Certified Lead Developer
    in reply to Dave Lewis

    Agreed - and further, a common pattern i've been noticing more and more lately is that newer devs will try to handle these somewhat more complicated UI formulas, without really having a good understanding of what the logic is actually doing, and why.  More learning and practice (and simplified example setups like the one you suggest) would go a long way into helping in most peoples' cases.