I'm having problems trying to update all the items in an array (copying the

Certified Senior Developer
I'm having problems trying to update all the items in an array (copying the value from one element into another) when the user clicks on a link.

As part of a user interface that captures fund allocations we want to be able to click on a single link/button/checkbox and for it to set the allocation percentage to 100 for all funds in an array and set the estimated value to the current value for each of those funds. The percentage field is editable whereas the estimated value is calculated based on the percentage (which works fine when calculated as part of the saveInto after the percentage is manually input).

The following code works fine but I need to be able to dynamically create the necessary a!save rows for each item in the local!items array:

a!linkField(
links: a!dynamicLink(
label: "Disinvest all funds",
value: 100,
saveInto: {
local!items.percentageToSwitch,
a!save(...

OriginalPostID-146618

OriginalPostID-146618

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer
    ...local!items[1].estimatedAmount,local!items[1].currentFundValue),
    a!save(local!items[2].estimatedAmount,local!items[2].currentFundValue),
    a!save(local!items[3].estimatedAmount,local!items[3].currentFundValue),
    }
    )

    I've been trying various versions of apply and applycomponents but have so far not been able to get this to work. Has anyone else solved a similar problem and if so how do you resolve it?

    Thanks.
  • 0
    Certified Lead Developer
    using applycomponents your subrule should take the following parameters:

    items: your items array
    index: a generated list of indexes for items in the array
    valueToSave: your value to save (in this case 100)

    inside the rule you should do a!save(ri!items[ri!index], ri!valueToSave)

    Let me know if that works and if you have any questions.
  • 0
    Certified Senior Developer
    Thanks for the response, as is usual with these things no sooner had I posted this than I managed to resolve the issue myself (but I'll try your solution as well to compare the two).

    I used a rule with a single input - index (Integer) as follows:
    = a!save(
    local!items[ri!index].estimatedAmount,
    local!items[ri!index].currentFundValue
    )

    And then an apply within my saveInto:
    saveInto: {
    local!items.percentageToSwitch,
    apply(rule!IWTS_saveEstimatedAmountToCurrentValue,where(local!items.percentageToSwitch=100)),
    }
  • 0
    Certified Senior Developer
    And I've just noticed I've misnamed my rule as it's actually saving the current value to the estimated amount and not the other way around. Doh!