Reevaluating Flow Hr Activity set trigger check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 2 weeks ago
Putting this here so someone doesn't waste too much time on it.
With workflows, you could force a reevaluation of activity set triggers using the script below (available in the "Condition with Event BR (Demo)" business rule if you have it) :
(function executeRule(current, previous /*null when async*/) {
var wf = new global.Workflow().getRunningFlows(current);
while (wf.next()) {
if (wf.getValue('name') == 'HR Activity Set Trigger Check')
new global.Workflow().broadcastEvent(wf.sys_id, 'check_activity_set_trigger');
}
})(current, previous);But, since moving almost everything to flows, this does not work anymore.
You can fix this tho by simply changing the flow name from "HR Activity Set Trigger Check" to "Wait for Workflow Event". The new script looks like this :
(function executeRule(current, previous /*null when async*/) {
var wf = new global.Workflow().getRunningFlows(current);
while (wf.next()) {
if (wf.getValue('name') == 'Wait for Workflow Event')
new global.Workflow().broadcastEvent(wf.sys_id, 'check_activity_set_trigger');
}
})(current, previous);You can check the activity set trigger subflows if you're curious about the details
----------------------------------------------------------------------------------------------------------------------------------------
UPDATE :
Everything above works on yokohama. With the zurich release, the "Wait for Workflow Event" workflow is not used anymore, and theres a different logic in the "Wait for a event and check trigger" subflow. Now it uses the "Wait For Message" action to trigger the evaluation.
To make things short, there's no simple way like the one above to force the reevaluation, and the OOB business rules that did so have disappeared.
I had to make a workaround :
// Get all HR Activity Set Context records linked to the given HR case
var grSHLASC = new GlideRecord('sn_hr_le_activity_set_context');
grSHLASC.addEncodedQuery("hr_case=" + your_case_sys_id);
//You can add a query here to only get "Hr Activity Launcher" flow contexts
grSHLASC.query();
while (grSHLASC.next()) {
// Find the "HR Activity Set Trigger Check" flow context whose source_record is the flow_context on the current activity set context
var grSFCCheck = new GlideRecord('sys_flow_context');
grSFCCheck.addEncodedQuery(
"source_record=" + grSHLASC.flow_context + "^name=HR Activity Set Trigger Check"
);
grSFCCheck.query();
while (grSFCCheck.next()) {
// For each of those, find the *child* flow context that is actually waiting for the event: "Wait for a event and check trigger"
var grSFC = new GlideRecord('sys_flow_context');
grSFC.addEncodedQuery(
"source_record=" + grSFCCheck.sys_id + "^name=Wait for a event and check trigger"
);
grSFC.query();
while (grSFC.next()) {
// sys_id of the paused flow to send the message to
var flowId = grSFC.getValue("sys_id");
// Message key the Flow was waiting on in the "Wait for event" step
var resumeMessage = 'check_activity_set_trigger';
// Payload data sent back to the Flow (accessible in the Flow context) -- You can put anything in here
var payload = 'Activities triggered from script X';
// Send the event message to resume the paused Flow
var result = sn_fd.FlowAPI.sendMessage(flowId, resumeMessage, payload);
}
}
}cheers
