16/23

Dynamic Transaction Risk Analyzer

Medium

You are given a list of customer transactions. Each transaction contains:

  1. customer
  2. amount
  3. type — "CREDIT" or "DEBIT"
  4. status — "SUCCESS" or "FAILED"


Your task is to build an Appian expression that:

  1. Ignores all failed transactions.
  2. For each customer, calculate their net transaction amount:
  3. CREDIT → add the amount
  4. DEBIT → subtract the amount
  5. Assign a risk level:
  6. HIGH → net amount < -5000
  7. MEDIUM → net amount between -5000 and 0
  8. LOW → net amount > 0
  9. Return only customers with HIGH or MEDIUM risk.
  10. Sort the result by:
  11. HIGH risk first
  12. MEDIUM risk second
  13. Within the same risk level, lowest net amount first.
  14. Return the final result in this format:
{
{customer: "John", netAmount: -7200, risk: "HIGH"},
{customer: "David", netAmount: -2500, risk: "MEDIUM"}
}



ri! Rule Inputs

ri!transactionsList of Map
{
  {customer: "John", amount: 4000, type: "CREDIT", status: "SUCCESS"},
  {customer: "John", amount: 12000, type: "DEBIT", status: "SUCCESS"},
  {customer: "John", amount: 3000, type: "CREDIT", status: "FAILED"},
  {customer: "David", amount: 2000, type: "CREDIT", status: "SUCCESS"},
  {customer: "David", amount: 4500, type: "DEBIT", status: "SUCCESS"},
  {customer: "Sarah", amount: 10000, type: "CREDIT", status: "SUCCESS"},
  {customer: "Sarah", amount: 2000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Mike", amount: 1000, type: "CREDIT", status: "FAILED"},
  {customer: "Mike", amount: 6000, type: "DEBIT", status: "SUCCESS"}
}

Example 1 — Case 1

Input: ri!transactions
{
  {customer: "John", amount: 4000, type: "CREDIT", status: "SUCCESS"},
  {customer: "John", amount: 12000, type: "DEBIT", status: "SUCCESS"},
  {customer: "John", amount: 3000, type: "CREDIT", status: "FAILED"},
  {customer: "David", amount: 2000, type: "CREDIT", status: "SUCCESS"},
  {customer: "David", amount: 4500, type: "DEBIT", status: "SUCCESS"},
  {customer: "Sarah", amount: 10000, type: "CREDIT", status: "SUCCESS"},
  {customer: "Sarah", amount: 2000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Mike", amount: 1000, type: "CREDIT", status: "FAILED"},
  {customer: "Mike", amount: 6000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Mike", amount: 10000, type: "DEBIT", status: "SUCCESS"}
}
Output:
{
  a!map(customer: "Mike", netAmount: -16000.0, risk: "HIGH"),
  a!map(customer: "John", netAmount: -8000.0, risk: "HIGH"),
  a!map(customer: "David", netAmount: -2500.0, risk: "MEDIUM")
}

Example 2 — Case 2

Input: ri!transactions
{
  {customer: "Alice", amount: 5000, type: "CREDIT", status: "SUCCESS"},
  {customer: "Alice", amount: 10000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Bob", amount: 5000, type: "CREDIT", status: "SUCCESS"},
  {customer: "Bob", amount: 5000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Charlie", amount: 8000, type: "CREDIT", status: "SUCCESS"}
}
Output:
{
  a!map(customer: "Alice", netAmount: -5000.0, risk: "MEDIUM"),
  a!map(customer: "Bob", netAmount: 0.0, risk: "MEDIUM")
}

Example 3 — Case 3

Input: ri!transactions
{
  {customer: "Alex", amount: 10000, type: "DEBIT", status: "FAILED"},
  {customer: "Alex", amount: 3000, type: "CREDIT", status: "FAILED"},
  {customer: "Brian", amount: 2000, type: "CREDIT", status: "SUCCESS"},
  {customer: "Brian", amount: 9000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Chris", amount: 15000, type: "DEBIT", status: "SUCCESS"},
  {customer: "Chris", amount: 5000, type: "CREDIT", status: "FAILED"}
}
Output:
{
  a!map(customer: "Chris", netAmount: -15000.0, risk: "HIGH"),
  a!map(customer: "Brian", netAmount: -7000.0, risk: "HIGH")
}

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