How can you add new Activity Sets to an existing Lifecycle Event Case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 12:40 PM
Hello,
I'm in a situation where I need to add new Activity Sets to existing Lifecycle Event cases.
I'm adding some return to work activity sets at the end of Medical Leave Lifecycle Event HR service and would also like to incorporate them to existing cases in Prod that are currently active.
I've been able to run this as a Fix Script and successfully append the Activity Sets, however, when it gets time for them to trigger after the previous Activity Set closes, nothing happens.
I'm under the impression that records need to be added to the wf_context table for each of these.
Has anybody been faced with this type of situation and were you able to properly update existing cases?
// Define the Activity Set IDs and their corresponding Activities to be appended
var activitySets = {
'368296a447059250cce934b2846d437a': 'faddc69247709610cce934b2846d43dd', // Leader Checklist 500 - Support Leave
'438d029247709610cce934b2846d43e0': 'd5405e5647709610cce934b2846d43a8' // Return to Work - Confirmation 500 - Support Leave
};
// Initialize GlideRecord for HR Cases
var hrCaseGR = new GlideRecord('sn_hr_core_case');
hrCaseGR.addQuery('active', true); // Open cases
hrCaseGR.addQuery('hr_service', '95af8b8c4712bd10cce934b2846d43e8'); // Filter by Medical Leave of Service
hrCaseGR.query();
// Loop through each matching HR case
while (hrCaseGR.next()) {
gs.info('Processing HR Case: ' + hrCaseGR.number);
// Loop through each defined activity set and corresponding activity
for (var activitySetId in activitySets) {
if (activitySets.hasOwnProperty(activitySetId)) {
var activityId = activitySets[activitySetId];
// Create a new activity linked to the current Activity Set
var newActivity = new GlideRecord('sn_hr_le_activity_set_context');
newActivity.initialize();
newActivity.activity_set = activitySetId; // Set the Activity Set ID
newActivity.hr_case = hrCaseGR.sys_id; // Link to the HR Case
newActivity.state = 'awaiting_trigger';
newActivity.activity_set.display_order = '500'; // Update the display order as needed
//newActivity.workflow_context = '49572a4147919610b38f997f746d4375'; // Update the workflow context
newActivity.short_description = 'Appended Activity for Medical Leave: ' + activityId;
// Insert the new activity set
var newActivityId = newActivity.insert();
if (newActivityId) {
gs.info('Successfully appended Activity ' + activityId + ' to HR Case: ' + hrCaseGR.number);
} else {
gs.error('Failed to append Activity ' + activityId + ' to HR Case: ' + hrCaseGR.number);
}
}
}
}