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