pickerFieldCustom does not return "I have been used"

Hello everybody,
we have  an issue in  following scenario.

We are using a pickerFieldCustom to search for a given personal_code, from a table personalCodes.
(we adapted our code starting from a recipe exemple)

This table looks like:
id              PRIMARY
firstname
lastname
personal_code   UNIQUE

The desired goal is:
IF  the searched personal_code is found, then fill a section (read only) with all data retrieved from the table
ELSE open a new section to fill data above


The best we could do is just a workaround: a button to be pushed  to show the layout to be filled , when pickerFieldCustom does not return anything.
(but if you do NOT press button, layout is NOT shown)

I think that the issue arises because I do not know how to distinguish beetwen following two states:
(A) "pickerFieldCustom has been used" meaning that a value has been put into pickerFieldCustom, regardless the result has been found or not
(B) pickerFieldCustom has returned a result

This distinction is required to show different layouts, depending on previous states. In fact, I would realize: (in psedo-code)

if(state == (A)) {
    if (state == (B)) {
        show layout read-only
        }
    else {
        show layout to fill
    }
} else {
    // do nothing
}

Is it possible distinguish the two states above?

Any suggestion or hint will be very appreciated.

Thank you in advance, best regards.

Paolo

 

= load(
  local!personalcode: {},
  local!listPersonalCodes: {
    rule!getPersonalCode().personalcode
  },
  with(
    local!dati: rule!getPersonalData(
      local!personalcode
    ),
    a!formLayout(
      firstColumnContents: {
        a!pickerFieldCustom(
          label: "Search by Personal Code",
          placeholder: "Search Personal Code",
          maxSelections: 1,
          suggestFunction: rule!ucArrayPickerFilte(
            filter: _,
            labels: local!listPersonalCodes,
            identifiers: local!listPersonalCodes
          ),
          selectedLabels: if(
            or(
              isnull(
                local!personalcode
              ),
              count(
                local!personalcode
              ) = 0
            ),
            null,
            apply(
              rule!ucArrayPickerGetLabelForIdentifier(
                identifier: _,
                labels: local!listPersonalCodes,
                identifiers: local!listPersonalCodes
              ),
              local!personalcode
            )
          ),
          value: local!personalcode,
          saveInto: {
            local!personalcode,
            a!save(
              ri!pickerHasBeenUsed,
              true
            )
          }
        ),
        a!buttonLayout(
          secondaryButtons: {
            if(
              true,
              a!buttonWidget(
                label: "Value not found - Insert values",
                value: true(),
                saveInto: {
                  ri!valueNotFound,
                  a!save(
                    local!personalcode,
                    null
                  )
                }
              ),
              {}
            ),
            
          }
        ),
        if(
          ri!valueNotFound,
          a!sectionLayout(
            firstColumnContents: {
              if(
                rule!APN_isBlank(
                  local!personalcode
                ),
                a!textField(
                  label: "Personal Code",
                  value: ri!personalData.personalcode,
                  saveInto: ri!personalData.personalcode,
                  readOnly: false
                ),
                {}
              ),
              a!textField(
                label: "First Name",
                value: ri!personalData.firstname,
                saveInto: ri!personalData.firstname,
                readOnly: false
              ),
              a!textField(
                label: "Last Name",
                value: ri!personalData.lastname,
                saveInto: ri!personalData.lastname,
                readOnly: false
              ),
              
            }
          ),
          if(
            not(
              and(
                true,
                rule!APN_isBlank(
                  ri!pickerHasBeenUsed
                ),
                rule!APN_isBlank(
                  local!personalcode
                )
              )
            ),
            a!sectionLayout(
              firstColumnContents: {
                if(
                  and(
                    not(
                      isnull(
                        ri!valueNotFound
                      )
                    ),
                    isnull(
                      local!personalcode
                    )
                  ),
                  {},
                  a!textField(
                    label: "Personal Code",
                    value: local!personalcode,
                    saveInto: ri!personalData.personalcode,
                    readOnly: true
                  )
                ),
                if(
                  and(
                    not(
                      isnull(
                        ri!valueNotFound
                      )
                    ),
                    isnull(
                      local!personalcode
                    )
                  ),
                  {},
                  a!textField(
                    label: "First Name",
                    value: local!dati.firstname,
                    saveInto: ri!personalData.firstname,
                    readOnly: true
                  )
                ),
                if(
                  and(
                    not(
                      isnull(
                        ri!valueNotFound
                      )
                    ),
                    isnull(
                      local!personalcode
                    )
                  ),
                  {},
                  a!textField(
                    label: "Last Name",
                    value: local!dati.lastname,
                    saveInto: ri!personalData.lastname,
                    readOnly: true
                  )
                ),
                     
              }
            ),
            {}
          )
        )
      },
      secondColumnContents: {},
      buttons: a!buttonLayout(
        primaryButtons: a!buttonWidgetSubmit(
          label: "Submit",
          style: "PRIMARY",
          value: if(
            rule!APN_isBlank(
              local!personalcode
            ),
            ri!personalData,
            local!dati
          ),
          saveInto: {
            a!save(
              ri!personalData,
              save!value
            )
          }
        )
      )
    )
  )
)

  Discussion posts and replies are publicly visible

Parents
  • +2
    Certified Lead Developer

    As far as i can tell there's no way to save back a special value if nothing ends up being selected within the custom picker.

    However, while thinking about it, I was able to come up with a solution that might be workable for you.  So if you have to use custom picker and not some other combination of components, would be to modify your SuggestFunction and have it pass back a special datasubset when no results match the query being run as the user types into the picker field.  I just tried briefly in one of my existing picker components and I was able to get the picker to suggest a value of "(No Matches)" when typing an invalid value, and when selecting it, saving back a value of -1 for identifiers.  Then your main form could intercept this special identifier and kick in the new section you're wanting to show.

    Let me know if you need any clarifications on that - as far as I can tell it should work for you.

  • Thank you Mike.

    Following your suggestion, I attach here the "core" of solution, consisting in modification to the suggestFunction.

    Please remember that the starting point of suggestFunction was that one in the recipe here:  https://docs.appian.com/suite/help/17.1/recipe_configure_an_array_picker.html

    Hoping this can help someone.

    Regards.

    = load(
      with(
        local!matches: where(
          apply(
            search(
              ri!filter,
              _
            ),
            ri!labels
          )
        ),
        if(
          (
            /* no values found */
            length(
              local!matches
            ) = 0
          ),
    	  /* ADDED THE CASE OF NOT FOUND */
          'type!{http://www.appian.com/ae/types/2009}DataSubset'(
            data: {
              "RESULT NOT FOUND"
            },
            identifiers: {
    		 -1 
    		 /* should be better define here a constant like the following:
              *  cons!valueFor_RESULT_NOT_FOUND
    		  */
            }
          ),
          'type!{http://www.appian.com/ae/types/2009}DataSubset'(
            data: index(
              ri!labels,
              local!matches
            ),
            identifiers: index(
              ri!identifiers,
              local!matches
            )
          )
        )
      )
    )

Reply
  • Thank you Mike.

    Following your suggestion, I attach here the "core" of solution, consisting in modification to the suggestFunction.

    Please remember that the starting point of suggestFunction was that one in the recipe here:  https://docs.appian.com/suite/help/17.1/recipe_configure_an_array_picker.html

    Hoping this can help someone.

    Regards.

    = load(
      with(
        local!matches: where(
          apply(
            search(
              ri!filter,
              _
            ),
            ri!labels
          )
        ),
        if(
          (
            /* no values found */
            length(
              local!matches
            ) = 0
          ),
    	  /* ADDED THE CASE OF NOT FOUND */
          'type!{http://www.appian.com/ae/types/2009}DataSubset'(
            data: {
              "RESULT NOT FOUND"
            },
            identifiers: {
    		 -1 
    		 /* should be better define here a constant like the following:
              *  cons!valueFor_RESULT_NOT_FOUND
    		  */
            }
          ),
          'type!{http://www.appian.com/ae/types/2009}DataSubset'(
            data: index(
              ri!labels,
              local!matches
            ),
            identifiers: index(
              ri!identifiers,
              local!matches
            )
          )
        )
      )
    )

Children
No Data