# AddTaskBundleToClaim - Advanced Documentation ## Overview Adds a predefined task bundle (template) to a claim, creating all tasks defined in the bundle with calculated dates and staff assignments. Task bundles are firm-configured templates containing multiple tasks with relative date offsets. ## Date Calculation Each task in the bundle has `DaysUntilStart` and `DaysUntilDue` offsets. These are added to the `DaysUntilDueStartDate` parameter: - `DateStart = DaysUntilDueStartDate + task.DaysUntilStart` - `DateDue = DaysUntilDueStartDate + task.DaysUntilDue` ## Staff Role Resolution Task ownership is determined in priority order: 1. **Explicit StaffID** on the bundle task - assigned directly 2. **Staff Role** on the bundle task - matched against claim staff roles (case-insensitive). The first claim staff member with a matching role gets the task. 3. **Current Person** - fallback if no explicit staff or matching role The method loads claim staff via `GetClaimStaff` to resolve role-based assignments. ## What Gets Created For each task in the bundle: - Task record with calculated dates - Task name prefixed with `TaskBundlePrefix` - DigestReminders with computed reminder dates - Task category and owner assignment ## Script Example ```javascript async () => { const tasks = await SecureApi.AddTaskBundleToClaim( 42, // TaskBundleID new Date("2025-04-01"), // Launch date for date calculations "Initial Review", // Prefix for task names { ID: 771360, Name: "SmithJohn_PI_771360" } // Claim ); return tasks.map(t => ({ name: t.Name, owner: t.Owner?.Name, dateStart: t.DateStart, dateDue: t.DateDue })); } ``` ## Error Conditions - Any null parameter - throws ArgumentNullException - Invalid TaskBundleID - throws exception from GetTaskBundle - Task prefix validation failure - throws from ValidateTaskBundleTasks