Persist list of checkbox selections on records with related children

A Score Level 1

Hi,

I'm having difficulty finding the best approach to updating a list of checkbox options on a parent record using related record associations. Essentially, I am exploring the ability to save multiple selections (child rows) on the "create" of a new record and ability to "update" those persisted selections through an update process. I have a simple example expressed below through the use of local variables for clarity but hoping a few insights will help me understand how to apply at a recordType level with related record data. The content related to post# 22489 was very helpful but not fully understanding how we can add new items and also remove (inactivate the unselected items). The end result would be the use of a checkbox or multipledropdown field where a user can add new rows (isActive: true()) by selecting and unselect saved rows (set isActive: false()) to write back to the record table.

Sample code:

a!localVariables(
  local!supplyList: {
    { id: 1, item: "Pencil" },
    { id: 2, item: "Paper" },
    { id: 3, item: "Binder" },
    
  },
  local!student: {
    id: 1,
    name: "John Smith",
    suppliesNeeded: {},
    
  },
  local!selections,
  {
    a!checkboxField(
      label: "Choose Supplies",
      choiceLabels: index(local!supplyList, "item", null),
      choiceValues: index(local!supplyList, "id", null),
      value: local!selections,
      saveInto: {
        local!selections,
        a!save(
          target: local!student.suppliesNeeded,
          value: a!forEach(
            items: local!selections,
            expression: { 
              id: fv!item,
              isActive: true()
            }
          )
        )
      }
    )
  }
)

Screenshot of example in work: 



Any insight would be gladly appreciated!

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    From table perspective you have to create 2 tables - one for student and another one for supplylist with one to many relation. Your supplylist needs to have id (pk), studentid (fk) and name. When you edit student you need to get array from selection from supplylit for particular student. Then user can change selection (add new selection, remove previously selected item). I would store those user inputs in local variables that needs to be passed to process model. Remember to pass to removed items id value (unique). Process model needs to execute both -add new, delete removed. 

    I would use Write to Data Store Entity and Delete From data Store Entities smart services

  • 0
    Certified Senior Developer

    a!localVariables(
    local!supplyList: {
    { id: 1, item: "Pencil" },
    { id: 2, item: "Paper" },
    { id: 3, item: "Binder" },

    },
    local!student: {
    id: 1,
    name: "John Smith",
    suppliesNeeded: {},

    },
    local!selections,
    {
    a!checkboxField(
    label: "Choose Supplies",
    choiceLabels: index(local!supplyList, "item", null),
    choiceValues: index(local!supplyList, "id", null),
    value: local!selections,
    saveInto: {
    local!selections,
    a!save(
    target: local!student.suppliesNeeded,
    value: a!forEach(
    items: local!supplyList.id,
    expression: {
    id: fv!item,
    isActive: contains(tointeger(local!selections), fv!item)
    }
    )
    )
    }
    )
    }
    )

    Try above code.