Skip to content

Link Two Related Cases

Goal

Create an explicit relationship between the current case and another case selected by the user.

What You Will Learn

  • accept a related case identifier through process data
  • create Related, Child, or Duplicate case links
  • reject missing and self-referencing input

Difficulty and Estimated Time

  • Difficulty: Intermediate
  • Estimated time: 15 minutes

Assumed Knowledge

You should be familiar with case identifiers, form validation, and postwork scripts.

Required Reading

Prerequisites

  • two cases visible to the test user
  • a case-related process with a field named Relation/CaseId
  • a task marked as a case handler

Steps

Add the following postwork script to the task that confirms the relationship:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var relatedCaseId = $Xml.Evaluate('Relation/CaseId');

if (!relatedCaseId) {
    throw new Error('Select a related case.');
}

if (relatedCaseId.toLowerCase() === $Case.Id.toLowerCase()) {
    throw new Error('A case cannot be related to itself.');
}

$Case.AddLink(relatedCaseId, 'Related');

Use Child when the second case represents subordinate work, or Duplicate when it records the same issue. Keep the relation type fixed in the script unless users have a controlled reason to choose it.

How It Works

AddLink accepts a case object or GUID string. The runtime creates the selected relationship from the current case to the target case and returns the current case instance.

Verify the Result

Open both test cases and confirm that the relationship is visible with the expected type. Repeat with the current case ID and confirm that the validation prevents a self-link.

Failure and Edge Cases

  • A malformed or nonexistent case identifier causes the operation to fail.
  • Repeated execution can attempt to create the same relationship again.
  • A technically valid case can still be outside the user's authorized scope.

Security and Portability Notes

  • Populate the field from cases the current user is allowed to discover.
  • Do not reveal case subjects or identifiers from restricted channels.
  • Never embed case GUIDs from another environment.

What to Learn Next