Weird save behavior {"Apple","Banana"} to null

Certified Senior Developer

Hi.

I was setting up some save functionality for the one spot in my code that saves to a particular variable.

I had a rule that outputs null under certain conditions, but kept watching it show up as {null} instead.

I have tried to simplify the issue and have found saving into the localvariable something like {"Apple", "Banana"} results in straight null instead. 

What is happening in my interface?

If i save the same value to a random debug variable it works fine.

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Hello  

    Please share your code snippet and screenshots .

  • 0
    Certified Senior Developer
    in reply to Mathieu Drouin


    Originally there was just project_mou_status and its description.  We had a new requirement come in for sub statuses to be given as choosable based on the description.  

    It has been a pain but I managed to get all the logic down for mapping to these.  Everything in the rules works fine.  Just this local variable below seems to be tainted in some way permanently. 

    local!projectMouSubStatuses:if(a!isNullOrEmpty(local!projectMOU.statusId),
    null,
    a!forEach(
    local!projectMouStatuses,
    if(tointeger(fv!item.projectMouStatusId)=local!projectMOU.statusId,
    fv!item.subStatus,
    {}
    ))),

  • As you note that saving this value to a dummy variable works fine, is the value of local!projectMouSubStatuses also fine in the expression?  As this would be the same scenario, unless local!projectMouSubStatuses is becoming manipulated elsewhere.

    How is this local variable getting to the output of the expression rule, is the result just the variable itself or is there further logic?

    The case where saving {"Apple", "Banana"} also becomes null is interesting, and leads me to think the value is manipulated further along in the code..

  • 0
    Certified Senior Developer
    in reply to Chris

    The only other area it is being manipulated is a dropdown for saving into the 'Request Status' field. 
    This is due to the dropdown for 'Request status' directly altering what can be chosen for 'Request sub status'

    a!dropdownField(
                              choiceLabels: union(
                                index(local!projectMouStatuses,"description",""),
                                index(local!projectMouStatuses,"description","")
                              ),
                              choiceValues: enumerate( length(
                                union(
                                  index(local!projectMouStatuses,"description",""),
                                  index(local!projectMouStatuses,"description","")
                              )))+1,
                              label: "Request Status",
                              labelPosition: "ABOVE",
                              placeholder: "--- Select a Value ---",
                              value: local!requestStatusIndex,
                              saveInto: {
                                a!save(local!requestStatusIndex, save!value),
                                a!save(local!requestSubStatusIndex, null),
                                a!save(local!projectMouSubStatuses ,
                                a!localVariables(
                                  local!subSetLabels: rule!DSC01_calcSubStatusList(
                                    dataSubSet: local!projectMouStatusDatasubset,
                                    desc: index(
                                      local!projectMouStatusLabelsUnique,
                                      save!value
                                    )
                                  ),
                                  if(a!isNullOrEmpty(index(local!subSetLabels, 1,{})),
                                    {},
                                    local!subSetLabels
                                  )
                                )
                                ),
                                a!save(local!projectMou.statusId, 
                                  rule!DSC01_calcStatusId(
                                    dataSubSet: local!projectMouStatusDatasubset, 
                                    desc:index(local!projectMouStatusLabelsUnique,local!requestStatusIndex, null), 
                                    subStatus:index(local!projectMouSubStatuses, local!requestSubStatusIndex, null)
                                  )
                                )
                              },
                              searchDisplay: "AUTO",
                              required: true,
                              validations: {}
                            ),

  • Tough to wrap my head around it from these snippets.  What I would do here first is put a number of debugging paragraph fields on the form with different pieces of your local calculation, to see if we can identify the reason for nulls.  Such as:

    {
      a!paragraphField(
        label: "DEBUG",
        readOnly: true,
        value: local!projectMOU.statusId
      ),
      a!paragraphField(
        label: "DEBUG",
        readOnly: true,
        value: a!isNullOrEmpty(local!projectMOU.statusId)
      ),
      a!paragraphField(
        label: "DEBUG",
        readOnly: true,
        value: local!projectMouStatuses.projectMouStatusId
      ),
      a!paragraphField(
        label: "DEBUG",
        readOnly: true,
        value: local!projectMouStatuses.subStatus
      ),
      a!paragraphField(
        label: "DEBUG",
        readOnly: true,
        value: if(
          a!isNullOrEmpty(local!projectMOU.statusId),
          null,
          a!forEach(
            local!projectMouStatuses,
            if(tointeger(fv!item.projectMouStatusId)=local!projectMOU.statusId,
            fv!item.subStatus,
            {}
            )
          )
        )
      ),
    }

  • 0
    Certified Senior Developer
    in reply to Mathieu Drouin

    Ok so the real issue seems to be the act of assigning this code to a variable as the page loads, permanently taints the variable, and it cant be saved into normally.


    local!projectMouSubStatuses:if(a!isNullOrEmpty(local!projectMOU.statusId),
                                      null, 
                                      a!forEach(
                                        local!projectMouStatuses, 
                                        if((fv!item.description)=(local!projectMouStatuses[local!projectMOU.statusId].description), 
                                        fv!item.subStatus, 
                                        {}
                                      ))),

  • You can certainly save into a variable that is defaulted on form load, the exception is refresh variables with these settings cannot be saved into:

    refreshAlways (Boolean): When true, the value of this local variable will be refreshed after each user interaction and each interval refresh. Because the variable is continually refreshed, you cannot update its value by saving into it. Default: false.

    refreshInterval (Number (Decimal)): How often the variable value gets refreshed in minutes. When null, the variable will not be refreshed on an interval. Because the variable is periodically refreshed, you cannot update its value by saving into it. You can access the current value of the variable using fv!value (see the documentation for an example). Valid values: 0.5, 1, 2, 3, 4, 5, 10, 30, 60.

    Ex:

    a!localVariables(
      local!counter: 0,
      
      a!sideBySideLayout(
        items: {
          a!sideBySideItem(
            width: "MINIMIZE",
            item: a!buttonArrayLayout(
              align: "START",
              buttons: {
                a!buttonWidget(
                  label: "Increment",
                  value: 1+local!counter,
                  saveInto: local!counter
                )
              }
            )
          ),
          a!sideBySideItem(
            item: a!textField(
              label: "Count",
              value: local!counter,
              readOnly: true
            )
          )
        }
      )
    )