"Remove function" applied to each instance in a multiple mapped value rule input

Certified Associate Developer

Hi team

We're trying to enter data when we are considering software to deploy.

We've used the "Remove" function to avoid saving null values to our four filters table.

It works just fine if we are looking at a single title, but for multiple titles we can't make it work

PROBLEM:

  • When we upload multiple values the pv correctly contains all data for each instance.
  • The task generates the correct number of instances
  • If the assessor chooses "not necessary" on any one task we get an error when trying to complete the subsequent tasks
  • An Error Has Occurred

    • Expression evaluation error [evaluation ID = 4fdbd:bd846] in rule 'sal_fourfilterdetails' (called by rule 'sal_uiaddfourfilters') : An error occurred while executing a save: Expression evaluation error: Cannot update List of Map; using a scalar value to update a list of length (3)
  • The error does not appear when we choose "not necessary"

Here's a pic of the interface:

 

Primary Interface

a!localVariables(
  local!readOnly1,
  local!isNameUnique: true,
  local!steps: {
    a!map(label: "Four Filters"),
    a!map(label: "Review")
  },
  local!activeStep: 1,
  local!reviewStep: count(local!steps),
  local!readOnly: local!activeStep = local!reviewStep,
  local!progress: (local!activeStep - 1) / (count(local!steps) - 1) * 100,
  a!formLayout(
    titleBar: "Four Filters Assessment",
    isTitleBarFixed: false,
    showTitleBarDivider: true,
    contents: {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!milestoneField(
                label: "Milestone",
                labelPosition: "COLLAPSED",
                steps: local!steps.label,
                links: a!forEach(
                  items: local!steps,
                  expression: if(
                    fv!index <= local!activeStep,
                    a!dynamicLink(
                      saveInto: a!save(local!activeStep, fv!index)
                    ),
                    {}
                  )
                ),
                active: local!activeStep,
                orientation: "VERTICAL"
              )
            },
            width: "NARROW"
          ),
          a!columnLayout(
            contents: {
              a!sectionLayout(
                label: "Review",
                labelIcon: "search",
                showWhen: local!readOnly,
                divider: "ABOVE",
                dividerWeight: "MEDIUM",
                dividerColor: "SECONDARY",
                marginAbove: "NONE",
                marginBelow: "NONE"
              ),
              a!cardLayout(
                contents: {
                  a!sectionLayout(
                    label: "Software",
                    labelIcon: "code-fork",
                    labelSize: if(local!readOnly, "SMALL", "MEDIUM"),
                    labelColor: if(local!readOnly, "SECONDARY", "ACCENT"),
                    contents: {
                      rule!SAL_uiGlobalSoftwareDetails(
                        software: ri!mappedValue.software,
                        readOnly: true,
                        isnameunique: local!isNameUnique
                      )
                    },
                    divider: "ABOVE",
                    dividerWeight: "MEDIUM",
                    dividerColor: if(local!readOnly, "SECONDARY", "ACCENT"),
                    marginAbove: "NONE",
                    marginBelow: "STANDARD"
                  )
                },
                height: "AUTO",
                style: "NONE",
                padding: if(local!readOnly, "LESS", "NONE"),
                marginAbove: "NONE",
                marginBelow: "NONE",
                showBorder: false
              ),
              a!cardLayout(
                contents: {
                  a!sectionLayout(
                    label: "Four Filters",
                    labelIcon: "code-fork",
                    labelSize: if(local!readOnly, "SMALL", "MEDIUM"),
                    labelColor: if(local!readOnly, "SECONDARY", "ACCENT"),
                    contents: {
                      rule!SAL_FourFilterDetails(
                        fourFilters: ri!mappedValue.software['recordType!{3c22821a-4d0f-44ba-a24d-1a3895b73ee5}SAL Global Software.relationships.{d9a0fa60-451b-4217-9162-0fd4a2f90614}fourFilter'],
                        readOnly: local!readOnly1
                      )
                    },
                    divider: "ABOVE",
                    dividerWeight: "MEDIUM",
                    dividerColor: if(local!readOnly, "SECONDARY", "ACCENT"),
                    marginAbove: "STANDARD",
                    marginBelow: "STANDARD"
                  )
                },
                height: "AUTO",
                /*showWhen: local!activeStep > 1,*/
                style: "NONE",
                padding: if(local!readOnly, "LESS", "NONE"),
                marginAbove: "NONE",
                marginBelow: "NONE",
                showBorder: false
              ),
              a!progressBarField(
                label: "Progress Bar",
                labelPosition: "COLLAPSED",
                percentage: local!progress,
                style: "THIN"
              )
            }
          )
        }
      ),
      a!buttonLayout(
        primaryButtons: {
          a!buttonWidget(
            label: "Submit",
            icon: "check",
            submit: true,
            style: "SOLID",
            loadingIndicator: true,
            showWhen: local!readOnly,
            validate: true
          ),
          a!buttonWidget(
            label: "Next",
            icon: "step-forward",
            value: local!activeStep,
            saveInto: { a!save(local!activeStep, save!value + 1),a!save(local!readOnly1,true) },
            style: "SOLID",
            loadingIndicator: true,
            showWhen: not(local!activeStep = local!reviewStep),
            validate: true
          )
        },
        secondaryButtons: {
          a!buttonWidget(
            label: "Back",
            icon: "step-backward",
            value: local!activeStep,
            saveInto: { a!save(local!activeStep, save!value - 1),a!save(local!readOnly1,null) },
            submit: false,
            style: "OUTLINE",
            showWhen: local!readOnly,
            validate: true
          ),
          a!buttonWidget(
            label: "Not Required",
            icon: "times",
            value: true,
            saveInto: a!save(
              ri!mappedValue.software,
              remove(
                ri!mappedValue.software,
                'recordType!{3c22821a-4d0f-44ba-a24d-1a3895b73ee5}SAL Global Software.relationships.{d9a0fa60-451b-4217-9162-0fd4a2f90614}fourFilter'
              )
            ),
            submit: true,
            color: "SECONDARY",
            showWhen: not(local!activeStep = local!reviewStep),
            validate: false,
            confirmHeader: "Please confirm your decision.",
            confirmMessage: "Are you sure the Four Filters exercise is not required?"
          )
        }
      )
    },
    contentsWidth: "FULL"
  )
)

Nested Interface

a!localVariables(
  local!leaderSoftware,
  local!leaderVendor,
  local!coreSoftware,
  local!softwarePurpose,
  local!evidence:"Evidence not required",
  local!choiceLabels: " ",
  local!trueValue: true,
  local!falseValue: false,
  a!cardLayout(
    contents: {
      a!cardLayout(
        contents: {
          a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                item: a!checkboxField(
                  choiceLabels: { local!choiceLabels },
                  choiceValues: { local!trueValue },
                  label: "Software is a category leader",
                  labelPosition: "ADJACENT",
                  instructions: {},
                  value: if(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{c7b9821e-f662-4649-80ff-dcdf4571d9c8}leaderSoftware'] = local!trueValue,
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{c7b9821e-f662-4649-80ff-dcdf4571d9c8}leaderSoftware'],
                    null()
                  ),
                  saveInto: {
                    a!save(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{c7b9821e-f662-4649-80ff-dcdf4571d9c8}leaderSoftware'],
                      if(
                        rule!APP_isEmptyArray(save!value),
                        local!falseValue,
                        local!trueValue
                      )
                    ),
                    a!save(local!leaderSoftware,1)
                  },
                  required: true,
                  disabled: ri!readOnly,
                  choiceStyle: "STANDARD",
                  validations: {},
                  align: "LEFT"
                ),
                width: "AUTO"
              ),
              a!sideBySideItem(
                item: a!paragraphField(
                  label: "",
                  labelPosition: "ADJACENT",
                  placeholder: if(
                    rule!APP_isFalse(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{c7b9821e-f662-4649-80ff-dcdf4571d9c8}leaderSoftware']
                    ),
                    "Why are you choosing software that is not a category leader?",
                    "Please provide evidence of category leadership and list your sources"
                  ),
                  value: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{11e934cf-3a78-4ced-b539-5a5963877128}leaderSoftwareEvidence'],
                  saveInto: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{11e934cf-3a78-4ced-b539-5a5963877128}leaderSoftwareEvidence'],
                  refreshAfter: "UNFOCUS",
                  height: "MEDIUM",
                  showWhen: a!isNotNullOrEmpty(
                    local!leaderSoftware
                  ),
                  required: not(rule!APP_isTrue(ri!readOnly)),
                  readOnly: ri!readOnly,
                  validations: {}
                ),
                width: "AUTO",
                showWhen: true
              ),
              a!sideBySideItem(
                item: a!tagField(
                  labelPosition: "COLLAPSED",
                  tags: {
                    a!tagItem(
                      text: local!evidence,
                      backgroundColor: "SECONDARY",
                      showWhen: true
                    )
                  }
                ),
                showWhen: and(
                  rule!APP_isTrue(ri!readOnly),
                  rule!APP_isFalse(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{c7b9821e-f662-4649-80ff-dcdf4571d9c8}leaderSoftware']
                  )
                )
              )
            }
          ),
          a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                item: a!checkboxField(
                  choiceLabels: { local!choiceLabels },
                  choiceValues: { local!trueValue },
                  label: "Software will be used for its intended purpose",
                  labelPosition: "ADJACENT",
                  instructions: {},
                  value: if(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{68e7a175-4534-4836-aacc-5bfb0b4ac98f}softwarePurpose'] = local!trueValue,
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{68e7a175-4534-4836-aacc-5bfb0b4ac98f}softwarePurpose'],
                    null()
                  ),
                  saveInto: {
                    a!save(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{68e7a175-4534-4836-aacc-5bfb0b4ac98f}softwarePurpose'],
                      if(
                        rule!APP_isEmptyArray(save!value),
                        local!falseValue,
                        local!trueValue
                      )
                    ),
                    a!save(local!softwarePurpose,1)
                  },
                  required: true,
                  disabled: ri!readOnly,
                  choiceStyle: "STANDARD",
                  validations: {}
                ),
                width: "AUTO"
              ),
              a!sideBySideItem(
                item: a!paragraphField(
                  label: "",
                  labelPosition: "ADJACENT",
                  placeholder: if(
                    rule!APP_isFalse(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{68e7a175-4534-4836-aacc-5bfb0b4ac98f}softwarePurpose']
                    ),
                    "Why will this application not be used as designed?",
                    "Please specify for what purpose this software is required."
                  ),
                  value: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{403d1a89-d2e7-4d74-bb4c-da03d3b11709}softwarePurposeEvidence'],
                  saveInto: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{403d1a89-d2e7-4d74-bb4c-da03d3b11709}softwarePurposeEvidence'],
                  refreshAfter: "UNFOCUS",
                  height: "MEDIUM",
                  showWhen: a!isNotNullOrEmpty(
                  local!softwarePurpose
                  ),
                  required: not(rule!APP_isTrue(ri!readOnly)),
                  readOnly: ri!readOnly,
                  validations: {}
                ),
                width: "AUTO",
                showWhen: true
              ),
              a!sideBySideItem(
                item: a!tagField(
                  label: "Tag Field",
                  labelPosition: "COLLAPSED",
                  tags: {
                    a!tagItem(
                      text: local!evidence,
                      backgroundColor: "SECONDARY"
                    )
                  }
                ),
                showWhen: and(
                  rule!APP_isTrue(ri!readOnly),
                  rule!APP_isFalse(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{68e7a175-4534-4836-aacc-5bfb0b4ac98f}softwarePurpose']
                  )
                )
              )
            }
          ),
          a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                item: a!checkboxField(
                  choiceLabels: { local!choiceLabels },
                  choiceValues: { local!trueValue },
                  label: "Vendor is a market leader",
                  labelPosition: "ADJACENT",
                  instructions: {},
                  value: if(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{5d504e4c-8c3b-4ef2-a147-b9c0cb2cdbec}leaderVendor'] = local!trueValue,
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{5d504e4c-8c3b-4ef2-a147-b9c0cb2cdbec}leaderVendor'],
                    null()
                  ),
                  saveInto: {
                    a!save(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{5d504e4c-8c3b-4ef2-a147-b9c0cb2cdbec}leaderVendor'],
                      if(
                        rule!APP_isEmptyArray(save!value),
                        local!falseValue,
                        local!trueValue
                      )
                    ),
                    a!save(local!leaderVendor,1)
                  },
                  required: true,
                  disabled: ri!readOnly,
                  choiceStyle: "STANDARD",
                  validations: {},
                  align: "LEFT"
                )
              ),
              a!sideBySideItem(
                item: a!paragraphField(
                  label: "",
                  labelPosition: "ADJACENT",
                  placeholder: if(
                    rule!APP_isFalse(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{5d504e4c-8c3b-4ef2-a147-b9c0cb2cdbec}leaderVendor']
                    ),
                    "Why are you choosing a vendor that is not a market leader?",
                    "Please provide evidence of vendor status and list your sources"
                  ),
                  value: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{0a0e80e6-569a-4c9b-bd2e-fc5d673a9a52}leaderVendorEvidence'],
                  saveInto: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{0a0e80e6-569a-4c9b-bd2e-fc5d673a9a52}leaderVendorEvidence'],
                  refreshAfter: "UNFOCUS",
                  height: "MEDIUM",
                  showWhen: a!isNotNullOrEmpty(
                    local!leaderVendor
                  ),
                  required: not(rule!APP_isTrue(ri!readOnly)),
                  readOnly: ri!readOnly,
                  validations: {}
                ),
                width: "AUTO",
                showWhen: true
              ),
              a!sideBySideItem(
                item: a!tagField(
                  label: "Tag Field",
                  labelPosition: "COLLAPSED",
                  tags: {
                    a!tagItem(
                      text: local!evidence,
                      backgroundColor: "SECONDARY"
                    )
                  }
                ),
                showWhen: and(
                  rule!APP_isTrue(ri!readOnly),
                  rule!APP_isFalse(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{5d504e4c-8c3b-4ef2-a147-b9c0cb2cdbec}leaderVendor']
                  )
                )
              )
            }
          ),
          a!sideBySideLayout(
            items: {
              a!sideBySideItem(
                item: a!checkboxField(
                  choiceLabels: { local!choiceLabels },
                  choiceValues: { local!trueValue },
                  label: "Software is core to the vendor's business",
                  labelPosition: "ADJACENT",
                  instructions: {},
                  value: if(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{41239df6-f9ca-4099-90b3-a02ae811893f}coreSoftware'] = local!trueValue,
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{41239df6-f9ca-4099-90b3-a02ae811893f}coreSoftware'],
                    null()
                  ),
                  saveInto: {
                    a!save(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{41239df6-f9ca-4099-90b3-a02ae811893f}coreSoftware'],
                      if(
                        rule!APP_isEmptyArray(save!value),
                        local!falseValue,
                        local!trueValue
                      )
                    ),
                    a!save(local!coreSoftware,1)
                  },
                  required: true,
                  disabled: ri!readOnly,
                  choiceStyle: "STANDARD",
                  validations: {}
                ),
                width: "AUTO"
              ),
              a!sideBySideItem(
                item: a!paragraphField(
                  label: "",
                  labelPosition: "ADJACENT",
                  placeholder: if(
                    rule!APP_isFalse(
                      ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{41239df6-f9ca-4099-90b3-a02ae811893f}coreSoftware']
                    ),
                    "Why are you choosing software that is not core to the vendor's business?",
                    "Please provide evidence of software importance to vendor and list your sources."
                  ),
                  value: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{84f3f106-00ae-4586-ad28-5e0420715ff2}coreSoftwareEvidence'],
                  saveInto: ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{84f3f106-00ae-4586-ad28-5e0420715ff2}coreSoftwareEvidence'],
                  refreshAfter: "UNFOCUS",
                  height: "MEDIUM",
                  showWhen: a!isNotNullOrEmpty(
                   local!coreSoftware
                  ),
                  required: not(rule!APP_isTrue(ri!readOnly)),
                  readOnly: ri!readOnly,
                  validations: {}
                ),
                width: "AUTO",
                showWhen: true
              ),
              a!sideBySideItem(
                item: a!tagField(
                  label: "Tag Field",
                  labelPosition: "COLLAPSED",
                  tags: {
                    a!tagItem(
                      text: local!evidence,
                      backgroundColor: "SECONDARY"
                    )
                  }
                ),
                showWhen: and(
                  rule!APP_isTrue(ri!readOnly),
                  rule!APP_isFalse(
                    ri!fourFilters['recordType!{be75cdca-c510-4491-b5a5-536ea016e2db}SAL Four Filter.fields.{41239df6-f9ca-4099-90b3-a02ae811893f}coreSoftware']
                  )
                )
              )
            }
          )
        },
        height: "AUTO",
        style: "NONE",
        marginBelow: "NONE",
        showBorder: false
      )
    },
    height: "AUTO",
    style: "NONE",
    shape: "SEMI_ROUNDED",
    padding: "STANDARD",
    marginAbove: "NONE",
    marginBelow: "NONE",
    showBorder: true,
    showShadow: true
  )
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    The remove() function returns a single value but ri!mappedValue.software is a list when handling multiple items, causing the error.

    Replace remove() with a!forEach() and a!update() to handle both single and multiple items by setting the fourFilter relationship to null instead of removing it entirely.

    a!buttonWidget(
      label: "Not Required",
      icon: "times",
      value: true,
      saveInto: {
        a!save(
          ri!mappedValue,
          if(
            a!isNullOrEmpty(ri!mappedValue.software),
            ri!mappedValue,
            a!update(
              data: ri!mappedValue,
              index: "software", 
              value: if(
                count(ri!mappedValue.software) = 1,
                /* Single item case - use remove */
                remove(
                  ri!mappedValue.software,
                  'recordType!{3c22821a-4d0f-44ba-a24d-1a3895b73ee5}.relationships.{d9a0fa60-451b-4217-9162-0fd4a2f90614}'
                ),
                /* Multiple items case - set the relationship to null for ALL items */
                a!forEach(
                  items: ri!mappedValue.software,
                  expression: a!update(
                    data: fv!item,
                    index: 'recordType!{3c22821a-4d0f-44ba-a24d-1a3895b73ee5}.relationships.{d9a0fa60-451b-4217-9162-0fd4a2f90614}',
                    value: null
                  )
                )
              )
            )
          )
        )
      },
      submit: true,
      color: "SECONDARY",
      showWhen: not(local!activeStep = local!reviewStep),
      validate: false,
      confirmHeader: "Please confirm your decision.",
      confirmMessage: "Are you sure the Four Filters exercise is not required?"
    )


    Note: This will clear the fourFilter for all software items when clicked. If you need to update only one specific item, you must pass an index from your process model.

Reply
  • 0
    Certified Lead Developer

    The remove() function returns a single value but ri!mappedValue.software is a list when handling multiple items, causing the error.

    Replace remove() with a!forEach() and a!update() to handle both single and multiple items by setting the fourFilter relationship to null instead of removing it entirely.

    a!buttonWidget(
      label: "Not Required",
      icon: "times",
      value: true,
      saveInto: {
        a!save(
          ri!mappedValue,
          if(
            a!isNullOrEmpty(ri!mappedValue.software),
            ri!mappedValue,
            a!update(
              data: ri!mappedValue,
              index: "software", 
              value: if(
                count(ri!mappedValue.software) = 1,
                /* Single item case - use remove */
                remove(
                  ri!mappedValue.software,
                  'recordType!{3c22821a-4d0f-44ba-a24d-1a3895b73ee5}.relationships.{d9a0fa60-451b-4217-9162-0fd4a2f90614}'
                ),
                /* Multiple items case - set the relationship to null for ALL items */
                a!forEach(
                  items: ri!mappedValue.software,
                  expression: a!update(
                    data: fv!item,
                    index: 'recordType!{3c22821a-4d0f-44ba-a24d-1a3895b73ee5}.relationships.{d9a0fa60-451b-4217-9162-0fd4a2f90614}',
                    value: null
                  )
                )
              )
            )
          )
        )
      },
      submit: true,
      color: "SECONDARY",
      showWhen: not(local!activeStep = local!reviewStep),
      validate: false,
      confirmHeader: "Please confirm your decision.",
      confirmMessage: "Are you sure the Four Filters exercise is not required?"
    )


    Note: This will clear the fourFilter for all software items when clicked. If you need to update only one specific item, you must pass an index from your process model.

Children
No Data