Trouble updating array with information from another array

"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."

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.

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

Parents Reply Children
No Data