It appears that a!isnotnullorempty is not working the way I think it should.

I have a portal (yes a real portal) where parishes set their preferences for a speaker for Mission Co-Op Mission Sunday.

The interface has a dropdown where they select the parish they want to set preferences and sets a local variable, slectedParish.  Once the parish is selected, I load a local variable, selectedParishProfile. 

local!selectedParishProfile: if(
    a!isNotNullOrEmpty(local!selectedParish),
    rule!PMSO_getParishProfilebyParishID(local!selectedParish),
    null
  ),

Now, the parish may or may not have an existing profile. So the expression rule either returns the profile or null if one does not exist.

In the interface, I have a radio button field.  

a!radioButtonField(
    choiceLabels: { "Yes", "No" },
    choiceValues: { true, false },
    label: "Can the Parish Provide Lodging?",
    labelPosition: "ABOVE",
    value: local!selectedParishProfile[PMSO Parish Profile.fields.parishLodgingType'],
    saveInto:  local!selectedParishProfile[PMSO Parish Profile.fields.parishLodgingType'],
    required: true,
    choiceLayout: "COMPACT",
    choiceStyle: "STANDARD",
    spacing: "EVEN_MORE"
 ),

Now this throws an error when I select a parish that does not have a parish profile because the value is Null.

"A radio button component [label="Can the Parish Provide Lodging?"] has an invalid value for "value". All selected values must be present in the choiceValues array, but value was Rectory and choiceValues was true; false."

Therefore, I created a local variable parishLodging to set a default and use that in the Radio Button.

local!parishlodging: if(
    a!isNotNullOrEmpty(
    local!selectedParishProfile['recordType!PMSO Parish Profile.fields.parishLodging']
     ),
    local!selectedParishProfile['recordType!PMSO Parish Profile.fields.parishLodging'],
    false
 ),

This works until I start entering data into the selectedParishProfile record.  For some reason, the local variable parishLodging is changed from false to Null.  I don't understand why.  The a!isNotNullorEmpty function should see that the field is still Null and it should be set to false.

What am I missing here?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    The error message very clearly states that this local is far from being null ...

  • Sorry, when I was pulling out all the changes I made to troubleshoot, I picked the wrong field.  The error message is this.

    A radio button component [label="Can the Parish Provide Lodging?"] has an invalid value for "value". All selected values must be present in the choiceValues array, but value was and choiceValues was true; false.

    Here are some snippets of the local variable values.

    When the page first loads with no parish being selected.

    With a Parish being selected with no parish profile.

    With data being entered.  I am not editing the ParishLodging field.

    To me, the local variable parishlodging is being updated to Null by this:

    local!parishlodging: if(
        a!isNotNullOrEmpty(
        local!selectedParishProfile['recordType!PMSO Parish Profile.fields.parishLodging']
      ),
      local!selectedParishProfile['recordType!PMSO Parish Profile.fields.parishLodging'],
      false
    ),

    So the field parishLoding in the local variable, selectedParishProfile is empty or null, but his seems to be setting the local variable parishLoding to the value that is in the selectedParishProfile which is null or empty.

  • 0
    Certified Lead Developer
    in reply to Chris.Gillespie

    Your local variable (as i mentioned earlier) is not evaluating as "null()", but as an array containing one "null()" value, since the value you're basing it on is an array of 1 item.

    I assume the Radio Button component is objecting to this value.

    Case in point, compare the following behaviors:

    versus

    the real solution to this is to probably force your query that populates local!selectedParishProfile to evaluate as a single value instead of as an array of 1 item.

    local!selectedParishProfile: if(
      a!isNotNullOrEmpty(local!selectedParish),
      
      /* use index() here to force the local variable to evaluate as a single unit, not an array of 1 item */
      index(
        rule!PMSO_getParishProfilebyParishID(local!selectedParish),
        1,
        null()
      ),
      null()
    ),

Reply
  • 0
    Certified Lead Developer
    in reply to Chris.Gillespie

    Your local variable (as i mentioned earlier) is not evaluating as "null()", but as an array containing one "null()" value, since the value you're basing it on is an array of 1 item.

    I assume the Radio Button component is objecting to this value.

    Case in point, compare the following behaviors:

    versus

    the real solution to this is to probably force your query that populates local!selectedParishProfile to evaluate as a single value instead of as an array of 1 item.

    local!selectedParishProfile: if(
      a!isNotNullOrEmpty(local!selectedParish),
      
      /* use index() here to force the local variable to evaluate as a single unit, not an array of 1 item */
      index(
        rule!PMSO_getParishProfilebyParishID(local!selectedParish),
        1,
        null()
      ),
      null()
    ),

Children
No Data