Local Variable not refreshing inside forEach

Certified Associate Developer

Ok so, inside a forEach statement I define a local variable like so:

a!localVariables(
  local!routingChoices: a!refreshVariable(
    value: if(
      a!isNotNullOrEmpty(ri!inputData[local!currentIndex].routingAction[fv!index]),
      a!match(
        value: ri!inputData[local!currentIndex].routingAction[fv!index],
        equals: 6,
        then: {1,2},
        equals: 7,
        then: {1,3},
        equals: 8,
        then: {2,4},
        equals: 9,
        then: {2,3},
        equals: 10,
        then: {3,4},
        equals: 11,
        then: {1,2,3},
        equals: 12,
        then: {2,3,4},
        default: fv!value
      ),
      null()
    ),
    refreshOnReferencedVarChange: false(),
    refreshOnVarChange: local!sealCount
  ),

local!sealCount stores an integer and the forEach is set up to run "enumerate(local!sealCount)" times (so if local!sealCount = 2 the forEach runs twice).

Then, farther down in the interface, I have a dynamic link that acts as a "delete" button (it subtracts 1 from local!sealCount and deletes the data in ri!inputData that corresponds to the index being deleted).

I also have an "add" button that is also created with a dynamic link that adds 1 to local!sealCount and appends a null() value to the fields in ri!inputData.

The problem I'm running into is that, when I add a component with the add button, put some data into local!routingChoices (via a card selection component), delete that component with the delete button, and then add a component again, the data that I put into local!routingChoices is still there. However, I expected it to be null() because ri!inputData[local!currentIndex].routingAction[fv!index] = null() and local!sealCount changed so the local variable should re-evaluate.

Here's a simplified chain of events:

   1) Click "add" button (sealCount = 2 now)

    2) Save data to routingChoices and inputData

    3) Click "delete" button for that component (sealCount = 1 now)

    4) Click "add" button again (sealCount = 2 now) <-- routingChoices expected to be null() but instead retains values from step 2

Can anyone help me understand what is going on here and how to fix it so that, when the "add" button is pressed routingChoices will be null()?

(Also, if you need to ask for clarification on something definitely feel free)

Thank you!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    are you able to provide full sale code for that interface which help to understand all your local variable values. 

  • 0
    Certified Associate Developer
    in reply to Naresh

    Naresh,

    That would not be practical as the interface has about 1100 lines of code. However, I can explain all the local variables in the code block that I did not explain in the question:

    local!currentIndex: the forEach that I mentioned in the question is actually inside another forEach, and currentIndex saves the value of fv!index for the outer forEach so I can reference it in the inner forEach. In this situation its value is 1.

    local!routingChoices: stores an array of integers that are selected in a card choice component. It could be {1,2}, {3,4}, {3}, {1,3,4}, ect. In the saveInto of the card choice component I convert each possible combination into a single number that represents it and store it in ri!inputData[local!currentIndex].routingAction[fv!index]. In the match statement shown in my code, I am unconverting it from the rule input back to an array to store in the local variable and display in the card choice component.

    Hope this helps!

Reply
  • 0
    Certified Associate Developer
    in reply to Naresh

    Naresh,

    That would not be practical as the interface has about 1100 lines of code. However, I can explain all the local variables in the code block that I did not explain in the question:

    local!currentIndex: the forEach that I mentioned in the question is actually inside another forEach, and currentIndex saves the value of fv!index for the outer forEach so I can reference it in the inner forEach. In this situation its value is 1.

    local!routingChoices: stores an array of integers that are selected in a card choice component. It could be {1,2}, {3,4}, {3}, {1,3,4}, ect. In the saveInto of the card choice component I convert each possible combination into a single number that represents it and store it in ri!inputData[local!currentIndex].routingAction[fv!index]. In the match statement shown in my code, I am unconverting it from the rule input back to an array to store in the local variable and display in the card choice component.

    Hope this helps!

Children
No Data