- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:14 AM
Hello,
We are attempting to add the opened_by field from the Lifecycle event case table as the Mentor on a Journey. To do this we understand that we need to create a Business Rule on the sn_jny_journey table, but are running into difficulties when configuring the action. None of the options in the drop down are viable to create an action with so we are left to scripting in the action. When searching online or Community we have not been able to find anything. Any help with this problem would be greatly appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 08:54 AM - edited 11-09-2023 08:55 AM
Hi @rocio2
Seems your post was deleted. about a BR on the sn_hr_le_case table to update mentors on sn_jny_journey.
The BR I show is defined on the 'sn_jny_journey' table, and runs when updates are made to that record. As @aguanci screenshot of his/her BR shows. And it looks in 'sn_hr_core_case' (also works if sn_hr_le_case table is specified as sn_hr_le_case is a child of sn_hr_core_case, which has the fields jny_context and opened_by) for the 'opened_by' value (I tried that based on the xml posted). And that works in my PDI.
A BR defined on the 'sn_hr_le_case' table would differ. However your screenshot shows infoMessages from my code. So I'm confused as you say you made an update on the Lifecycle case and not the Journey record.
I've tried a BR on that table, Runs "After" for Insert/Update (since it'll update a record in the sn_jny_journey table). The Script follows
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var jnyRec = new GlideRecord('sn_jny_journey');
jnyRec.addQuery('sys_id', current.jny_context.toString());
jnyRec.query();
gs.addInfoMessage('BR Found ' + jnyRec.getRowCount() + ' Journey records for ' +current.jny_context.getDisplayValue());
if (jnyRec.next()) {
gs.addInfoMessage("Checking if mentor = " + current.opened_by.getDisplayValue() + " for " + current.number);
var mentorList = jnyRec.mentors.toString();
var openedBy = current.opened_by.toString();
// Check for existing values
if (mentorList.length > 0) {
// check to see if mentors allready has lifecycle events opended_by
if (mentorList.indexOf(openedBy) < 0) {
// Not present, will add
gs.addInfoMessage("Adding mentor = " + current.opened_by.getDisplayValue() + " to " + current.number);
jnyRec.mentors += ',' + openedBy;
}
}
else {
gs.addInfoMessage("Setting mentor = " + current.opened_by.getDisplayValue() + " to " + current.number);
jnyRec.mentors = openedBy;
}
gs.addInfoMessage("Mentors = " + jnyRec.mentors);
jnyRec.update();
}
else
gs.addInfoMessage("Did not find Journey record for " + current.jny_context);
})(current, previous);
And it is defined in the 'Human Resources: Lifecycle Events' application scope. After updates to cross scope access for sn_jny_journey. the BR works.
Please be clear on what is desired behavior, use specific table names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 09:53 AM - edited 11-10-2023 06:44 AM
Great, Feel free to comment out the 'gs.addInfoMessages();' I used to help debug the code. Maybe @aguanci can close this thread now.
@rocio2 You should add a Filter Condition on the BR defined on the sn_hr_le_case table that has "Journey", "is not empty". prevent the BR using an empty value of that field.