"I'm encountering an issue with updating an array in costAdjustments. The current code is setting the LengthOfMonth field to 6 for all items in the array, but I only want to update specific entries."
costAdjustments
LengthOfMonth
a!save( local!newEstimates2, local!newEstimates2: a!forEach( items: local!newEstimates, expression: a!update( fv!item, "costAdjustments", a!forEach( items: fv!item.costAdjustments, expression: a!update(fv!item, "LengthOfMonth", 6) ) ) ) )
This isn't exactly what I need. What I want to do is loop through newEstimates and pull data from local!uniqueContractPeriods, which contains three rows of data with the fields: period, periodType, startDate, endDate, noOfMonths, and noOfDays. When the contractPeriodNum in costAdjustments within newEstimates matches the period in uniqueContractPeriods, I want to update the LengthOfMonth in newEstimates with the value of noOfMonths from uniqueContractPeriods. Below is the code I've written.
newEstimates
local!uniqueContractPeriods
contractPeriodNum
period
uniqueContractPeriods
noOfMonths
a!save( local!newEstimates2, local!newEstimates2: a!forEach( items: local!newEstimates, expression: a!update( fv!item, "costAdjustments", a!forEach( items: local!uniqueContractPeriods, expression: if( fv!item.period = fv!item.costAdjustments.contractPeriodNum, a!update( fv!item, "LengthOfMonth", index( local!uniqueContractPeriods.noOfMonths, where( tostring(fv!item.period) = tostring(fv!item.costAdjustments.contractPeriodNum) ) ) ), fv!item ) ) ) ) )
I am sure it is a simple fix, but I have been working on it for a long time, any assistance would be great. Thank you.
Discussion posts and replies are publicly visible
Try using update() and wherecontains() in tandem
a!localVariables( local!newEstimates: { a!map( lengthOfMonth: 1, costAdjustments: a!map(contractPeriodNum: 11) ), a!map( lengthOfMonth: 2, costAdjustments: a!map(contractPeriodNum: 12) ), a!map( lengthOfMonth: 3, costAdjustments: a!map(contractPeriodNum: 13) ) }, local!uniqueContractPeriods: { a!map( period: 14, periodType: "TEST1", noOfMonths: 100, ), a!map( period: 11, periodType: "TEST2", noOfMonths: 200, ), a!map( period: 12, periodType: "TEST3", noOfMonths: 300, ) }, a!forEach( items: local!newEstimates, expression: if( a!isNullOrEmpty( wherecontains( fv!item.costAdjustments.contractPeriodNum, tointeger(local!uniqueContractPeriods.period) ) ), fv!item, a!update( fv!item, "lengthOfMonth", cast(1,index( local!uniqueContractPeriods.noOfMonths, wherecontains( fv!item.costAdjustments.contractPeriodNum, tointeger(local!uniqueContractPeriods.period) ), null )) ) ) ) )