- 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-07-2023 11:34 AM
Seems your business rule is defined on the wrong table. What is the table name of "LifeCycle Events table" in your instance? I don't see that in my PDI after activating the plugins. Go to the "Tables" module and find the table, post the actual table name here. Better yet, post the XML version of the corresponding sys_db_object record for the table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 06:18 AM
The table name for LifeCycle Events is sn_hr_le_case. As far as the sys_db_object, I am not sure this is correct, but is this what you're looking for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 08:31 AM - edited 11-08-2023 09:29 AM
That is the dictionary record for the 'jny_context' field. But now I see both tables you mention. And if I understand your goal correct, when a record in the 'sn_jny_journey' is created or updated, you want to update the mentors field with the value of 'opened_by' from the 'sn_hr_core_case' that references the specific 'sn_jny_journey' record. Since 'mentors' field can contain multiple values, logic for the BR defined on the 'sn_jny_journey' table would be:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var lcEvent = new GlideRecord('sn_hr_core_case');
lcEvent.addQuery('jny_context', current.sys_id.toString());
lcEvent.query();
if (lcEvent.next()) {
gs.addInfoMessage("Checking if mentor = " + lcEvent.opened_by.getDisplayValue() + " for " + current.number);
var mentorList = current.mentors.toString();
var openedBy = lcEvent.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 = " + lcEvent.opened_by.getDisplayValue() + " to " + current.number);
current.mentors += ',' + openedBy;
}
}
else {
gs.addInfoMessage("Setting mentor = " + lcEvent.opened_by.getDisplayValue() + " to " + current.number);
current.mentors = openedBy;
}
}
else
gs.addInfoMessage("Did not find Lifecycle Events record with Journey = " + current.number);
})(current, previous);
But, the sn_hr_le_case and the sn_jny_journey tables are in two different application scopes. You will need to add a 'cross-scope privilege' record:
to get the above to work. I created two records, 1 for "Journey Designer" to have read access to "Human Resources: Lifecycle Events" and a 2nd for "Human Resources: Lifecycle Events" to have read access to "Journey Designer". The BR is defined in the "Journey Designer" application scope.
Also, as a Journey can be added to a Lifecycle events record, do you want to update the Journey mentors when a Lifecycle Events records is created or updated? that would take a second business rule.
- 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:16 AM
Thank you so much!!!!!
This works perfectly!!!