Saving Local Variables in nested a!forEach to rule inputs

Certified Associate Developer

I essentially need to pass the data stored in a few local variables to rule inputs so I can use them to fill in a template. The local variables are inside a forEach statement nested inside another forEach statement (see code below). The long if statements in both saveInto parameters are my first attempt at this and if only one item is selected from the multiple dropdown, it works perfectly, but if more than one item is chosen, each item overwrites the previous item instead of being saved into their own variables. 

Does anyone have an idea of how make this work or have a better idea of how to accomplish this? Thanks!

 

a!multipleDropdownField(
                    label: if(
                      or(
                        ri!SealModel = "DRC",
                        ri!SealModel = "DTP",
                        ri!SealModel = "DRP",
                        ri!SealModel = "SMD",
                        ri!SealModel = "DGS",
                        ri!SealModel = "EDP",
                        ri!SealModel = "RBD",
                        ri!SealModel = "ESD",
                        ri!SealModel = "UMC",
                        ri!SealModel = "PRO",
                        ri!SealModel = "PDM",
                        ri!SealModel = "KMS"
                      ),
                      "Inboard Rotary Face:",
                      "Rotary Face:"
                    ),
                    labelPosition: "ABOVE",
                    placeholder: "Choose symptoms",
                    choiceLabels: {
                      "Missing",
                      "Carbon Dusting",
                      "Chipped",
                      "Cracked",
                      "Broken",
                      "Corroded",
                      "Pitted",
                      "Eroded",
                      "Leached",
                      "Blistered",
                      "Heat Checked",
                      "Thermal Markings",
                      "Product Residue",
                      "Rubbed",
                      "Worn",
                      "Grooved",
                      "Heavily Damaged",
                      "Plugged",
                      "Dented"
                    },
                    choiceValues: {
                      "Missing",
                      "Carbon Dusting",
                      "Chipped",
                      "Cracked",
                      "Broken",
                      "Corroded",
                      "Pitted",
                      "Eroded",
                      "Leached",
                      "Blistered",
                      "Heat Checked",
                      "Thermal Markings",
                      "Product Residue",
                      "Rubbed",
                      "Worn",
                      "Grooved",
                      "Heavily Damaged",
                      "Plugged",
                      "Dented"
                    },
                    value: ri!IBRotFaceSym,
                    saveInto: ri!IBRotFaceSym,
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                )
              },
              alignVertical: "MIDDLE"
            ),
            /* IB Rotary Face */
            a!forEach(
              ri!IBRotFaceSym,
              a!localVariables(
                local!numarray: { 1 },
                local!Label: fv!item,
                a!forEach(
                  local!numarray,
                  a!localVariables(
                    local!Sev,
                    local!Loc,
                    local!Pic,
                    local!num: index(local!numarray, length(local!numarray)),
                    a!columnsLayout(
                      columns: {
                        a!columnLayout(
                          contents: {
                            a!sideBySideLayout(
                              items: {
                                a!sideBySideItem(
                                  item: a!dropdownField(
                                    label: local!Label & " Severity",
                                    labelPosition: "ADJACENT",
                                    placeholder: "--- Select a Value ---",
                                    choiceLabels: {
                                      "N/A",
                                      "Light",
                                      "Moderate",
                                      "Heavy",
                                      "Extreme"
                                    },
                                    choiceValues: {
                                      "N/A",
                                      "Light",
                                      "Moderate",
                                      "Heavy",
                                      "Extreme"
                                    },
                                    value: local!Sev,
                                    saveInto: {local!Sev, 
                                      a!save(if(contains(ri!IBRotFaceSym, "Missing"), ri!MissingSev[fv!index], 
                                      if(contains(ri!IBRotFaceSym, "Carbon Dusting"), ri!CarbDustSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Chipped"), ri!ChippedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Cracked"), ri!CrackedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Broken"), ri!BrokenSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Corroded"), ri!CorrodedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Pitted"), ri!PittedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Eroded"), ri!ErodedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Leached"), ri!LeachedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Blistered"), ri!BlisteredSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Heat Checked"), ri!CarbDustSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Thermal Markings"), ri!ThermMarkSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Product Residue"), ri!ProdResSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Rubbed"), ri!RubbedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Worn"), ri!WornSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Grooved"), ri!GroovedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Heavily Damaged"), ri!HeavyDamSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Plugged"), ri!PluggedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Dented"), ri!DentedSev[fv!index],
                                      null))))))))))))))))))),
                                      local!Label & " " & local!Sev & " " & local!Loc & " " & fv!index)},
                                    validations: {}
                                  )
                                ),
                                a!sideBySideItem(
                                  item: a!dropdownField(
                                    label: local!Label & " Location",
                                    labelPosition: "ADJACENT",
                                    placeholder: "--- Select a Value ---",
                                    choiceLabels: {
                                      "N/A",
                                      "ID",
                                      "OD",
                                      "Face",
                                      "Face ID",
                                      "Face OD",
                                      "Pin Slot",
                                      "Multiple Locations"
                                    },
                                    choiceValues: {
                                      "N/A",
                                      "ID",
                                      "OD",
                                      "Face",
                                      "Face ID",
                                      "Face OD",
                                      "Pin Slot",
                                      "Multiple Locations"
                                    },
                                    value: local!Loc,
                                    saveInto: { local!Loc, a!save(
                                      if(contains(ri!IBRotFaceSym, "Missing"), ri!MissingSev[fv!index], 
                                      if(contains(ri!IBRotFaceSym, "Carbon Dusting"), ri!CarbDustSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Chipped"), ri!ChippedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Cracked"), ri!CrackedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Broken"), ri!BrokenSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Corroded"), ri!CorrodedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Pitted"), ri!PittedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Eroded"), ri!ErodedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Leached"), ri!LeachedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Blistered"), ri!BlisteredSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Heat Checked"), ri!HeatCheckSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Thermal Markings"), ri!ThermMarkSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Product Residue"), ri!ProdResSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Rubbed"), ri!RubbedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Worn"), ri!WornSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Grooved"), ri!GroovedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Heavily Damaged"), ri!HeavyDamSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Plugged"), ri!PluggedSev[fv!index],
                                      if(contains(ri!IBRotFaceSym, "Dented"), ri!DentedSev[fv!index],
                                      null))))))))))))))))))),
                                      local!Label & " " & local!Sev & " " & local!Loc & " " & fv!index),
                                    a!save(ri!IBRotFaceSev, {ri!MissingSev; ri!CarbDustSev; ri!ChippedSev; 
                                      ri!CrackedSev; ri!BrokenSev; ri!CorrodedSev; ri!PittedSev; ri!ErodedSev;
                                      ri!LeachedSev; ri!BlisteredSev; ri!CarbDustSev; ri!ThermMarkSev; 
                                      ri!ProdResSev; ri!RubbedSev; ri!WornSev; ri!GroovedSev; ri!HeavyDamSev;
                                      ri!PluggedSev; ri!DentedSev})},
                                    searchDisplay: "AUTO",
                                    validations: {}
                                  )
                                ),
                                a!sideBySideItem(
                                  item: a!fileUploadField(
                                    label: "Upload Photos",
                                    labelPosition: "ADJACENT",
                                    target: cons!IBRotFacePics,
                                    fileNames: ri!ControlNumber & " IB Rotary Face " & local!Label & " " & fv!index,
                                    value: local!Pic,
                                    saveInto: local!Pic,
                                    validations: {},
                                    buttonStyle: "SECONDARY"
                                  ),
                                  width: "MINIMIZE"
                                )
                              }
                            ),
                            a!sideBySideLayout(
                              items: {
                                a!sideBySideItem(
                                  item: a!linkField(
                                    links: {
                                      a!dynamicLink(
                                        label: "Add Location",
                                        value: append(local!numarray, local!num + 1),
                                        saveInto: local!numarray,
                                        showWhen: if(
                                          local!numarray[length(local!numarray)] =< fv!item,
                                          true(),
                                          false()
                                        )
                                      )
                                    }
                                  ),
                                  width: "MINIMIZE"
                                ),
                                a!sideBySideItem(
                                  item: a!linkField(
                                    links: {
                                      a!dynamicLink(
                                        label: "Remove Location",
                                        value: remove(local!numarray, fv!index),
                                        saveInto: {local!numarray, 
                                        a!save(ri!MissingSev, remove(ri!MissingSev, fv!index))}
                                      )
                                    }
                                  ),
                                  width: "MINIMIZE"
                                )
                              }
                            )
                          }
                        )
                      }
                    )
                  )
                )
              )
            ),

  Discussion posts and replies are publicly visible

  • +1
    Certified Associate Developer

    If anyone is interested, I found a better way to do this. I basically replaced all of the code in my original question with an editable grid with an add row button. I also mapped the three dropdown fields that make up a row to one local variable, which is saved into a rule input (text array) when the last field is completed (see code below). This solution doesn't look quite as nice, but it works far better than my previous attempt.

    a!localVariables(
                  local!IBRotFaceSev: {
                    a!map(
                      Sym: "Choose Symptom",
                      Sev: "Select Severity Level",
                      Loc: "Select Location"
                    )
                  },
                  a!gridLayout(
                    label: if(
                      or(
                        ri!SealModel = "DRC",
                        ri!SealModel = "DTP",
                        ri!SealModel = "DRP",
                        ri!SealModel = "SMD",
                        ri!SealModel = "DGS",
                        ri!SealModel = "EDP",
                        ri!SealModel = "RBD",
                        ri!SealModel = "ESD",
                        ri!SealModel = "UMC",
                        ri!SealModel = "PRO",
                        ri!SealModel = "PDM",
                        ri!SealModel = "KMS"
                      ),
                      "Inboard Rotary Face:",
                      "Rotary Face:"
                    ),
                    headerCells: {
                      a!gridLayoutHeaderCell(label: "Symptom"),
                      a!gridLayoutHeaderCell(label: "Severity"),
                      a!gridLayoutHeaderCell(label: "Location"),
                      a!gridLayoutHeaderCell(label: "")
                    },
                    columnConfigs: {
                      a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                      a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                      a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
                      a!gridLayoutColumnConfig(width: "ICON")
                    },
                    rows: a!forEach(
                      local!IBRotFaceSev,
                      a!gridRowLayout(
                        id: fv!index,
                        contents: {
                          a!dropdownField(
                            label: "Symptom",
                            placeholder: "--- Select a Value ---",
                            choiceLabels: {
                              "Choose Symptom",
                              "Missing",
                              "Carbon Dusting",
                              "Chipped",
                              "Cracked",
                              "Broken",
                              "Corroded",
                              "Pitted",
                              "Eroded",
                              "Leached",
                              "Blistered",
                              "Heat Checked",
                              "Thermal Markings",
                              "Product Residue",
                              "Rubbed",
                              "Worn",
                              "Grooved",
                              "Heavily Damaged",
                              "Plugged",
                              "Dented"
                            },
                            choiceValues: {
                              "Choose Symptom",
                              "Missing",
                              "Carbon Dusting",
                              "Chipped",
                              "Cracked",
                              "Broken",
                              "Corroded",
                              "Pitted",
                              "Eroded",
                              "Leached",
                              "Blistered",
                              "Heat Checked",
                              "Thermal Markings",
                              "Product Residue",
                              "Rubbed",
                              "Worn",
                              "Grooved",
                              "Heavily Damaged",
                              "Plugged",
                              "Dented"
                            },
                            value: local!IBRotFaceSev[fv!index].Sym,
                            saveInto: local!IBRotFaceSev[fv!index].Sym,
                            validations: {}
                          ),
                          a!dropdownField(
                            label: "Severity",
                            labelPosition: "ADJACENT",
                            placeholder: "--- Select a Value ---",
                            choiceLabels: {
                              "Select Severity Level",
                              "N/A",
                              "Light",
                              "Moderate",
                              "Heavy",
                              "Extreme"
                            },
                            choiceValues: {
                              "Select Severity Level",
                              "N/A",
                              "Light",
                              "Moderate",
                              "Heavy",
                              "Extreme"
                            },
                            value: local!IBRotFaceSev[fv!index].Sev,
                            saveInto: local!IBRotFaceSev[fv!index].Sev,
                            validations: {}
                          ),
                          a!dropdownField(
                            label: "Location",
                            labelPosition: "ADJACENT",
                            placeholder: "--- Select a Value ---",
                            choiceLabels: {
                              "Select Location",
                              "N/A",
                              "ID",
                              "OD",
                              "Face",
                              "Face ID",
                              "Face OD",
                              "Pin Slot",
                              "Multiple Locations"
                            },
                            choiceValues: {
                              "Select Location",
                              "N/A",
                              "ID",
                              "OD",
                              "Face",
                              "Face ID",
                              "Face OD",
                              "Pin Slot",
                              "Multiple Locations"
                            },
                            value: local!IBRotFaceSev[fv!index].Loc,
                            saveInto: {
                              local!IBRotFaceSev[fv!index].Loc,
                              a!save(ri!IBRotFaceSev, local!IBRotFaceSev)
                            },
                            searchDisplay: "AUTO",
                            validations: {}
                          ),
                          a!richTextDisplayField(
                            value: a!richTextIcon(
                              icon: "close",
                              altText: "delete " & fv!index,
                              caption: "Remove " & local!IBRotFaceSev.Sym & ", " & local!IBRotFaceSev.Sev & ", " & local!IBRotFaceSev.Loc,
                              link: a!dynamicLink(
                                value: fv!index,
                                saveInto: {
                                  a!save(
                                    local!IBRotFaceSev,
                                    remove(local!IBRotFaceSev, save!value)
                                  ),
                                  a!save(
                                    ri!IBRotFaceSev,
                                    local!IBRotFaceSev
                                  )
                                }
                              ),
                              linkStyle: "STANDALONE",
                              color: "NEGATIVE"
                            )
                          )
                        }
                      )
                    ),
                    addRowLink: a!dynamicLink(
                      label: "Add Location",
                      value: {
                        Sym: "Choose Symptom",
                        Sev: "Select Severity Level",
                        Loc: "Select Location"
                      },
                      saveInto: {
                        a!save(
                          local!IBRotFaceSev,
                          append(local!IBRotFaceSev, save!value)
                        )
                      }
                    ),
                    rowHeader: 1
                  )
                ), /* IB Rotary Face */

  • 0
    Certified Lead Developer
    in reply to Jack Ferguson

    FYI, you could save yourself some trouble by declaring your dropdown label/value arrays as local variables (i.e. local!symptomChoices, etc), which would increase readability in your dropdown object declarations as well as reduce the work needed to add/update entries in the future.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Good point, thanks for the advice!

  • To add to Mikes suggestion, did you think about putting the values in constants? This would help a lot in maintenance when you use these values across multiple interfaces.