5/5

a!map(): merge a form into a customer record

Hard

A support agent edits a customer through a form. The form sends only the fields that were touched, as a record of changes.

Merge the changes into the customer

  • a field the customer record has — take the new value
  • a field the customer record has, sent blank — keep the old value; an empty box is not an edit
  • a field the customer record does not have — do not add it; list its name instead

Return a record with two fields

  • customer — the merged customer
  • ignored — the names of the unknown fields, in the order the form sent them

Watch out

  • Records are replaced rather than changed, so the merged customer is whatever the update gives back.
  • a!keys() lists a record's field names.

Inputs

  • ri!customer — Map
  • ri!changes — Map

ri! Rule Inputs

ri!customerMap
a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100")
ri!changesMap
a!map(city: "Delhi", phone: "555-0199", nickname: "Annie")

Example 1 — Two edits and an unknown field

Input: ri!customer
a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100")
Input: ri!changes
a!map(city: "Delhi", phone: "555-0199", nickname: "Annie")
Output:
a!map(customer: a!map(id: 7, name: "Ann", city: "Delhi", phone: "555-0199"), ignored: {"nickname"})

Example 2 — An empty box is not an edit

Input: ri!customer
a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100")
Input: ri!changes
a!map(city: "", name: "Ann Rao")
Output:
a!map(customer: a!map(id: 7, name: "Ann Rao", city: "Pune", phone: "555-0100"), ignored: {})

Example 3 — Nothing the record knows about

Input: ri!customer
a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100")
Input: ri!changes
a!map(nickname: "Annie", age: 30)
Output:
a!map(customer: a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100"), ignored: {"nickname", "age"})

Example 4 — An empty form

Input: ri!customer
a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100")
Input: ri!changes
a!map()
Output:
a!map(customer: a!map(id: 7, name: "Ann", city: "Pune", phone: "555-0100"), ignored: {})

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter