help with Business role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 01:37 PM
Guys, please help me, I'm trying to do a business role where, I take the input journal that a user made and send it to another table, and I have to do the same thing in another table.
I have the tables: x_1316384_terca_problema, x_1316384_terca_resposta. The 2 tables inherited the fields from the 'task' table, and I am using the 'number' and 'comments' fields. What I have so far is a business role that takes the record created in the x_1316384_terca_problema table and creates it in the x_1316384_terca_resposta table:
(function executeRule(current, previous /*null when async*/) {
var responseRecord = new GlideRecord('x_1316384_terca_resposta');
responseRecord.initialize();
responseRecord.comments = current.comments;
responseRecord.number = current.number;
responseRecord.insert();
})(current, previous);
and how would I do it the other way around? the objective is to somehow establish a conversation between the input journals of each table being referenced by 'number'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 02:10 PM
Hi, normal practice would be 1 BR on each table that would update the related record on the other table.
It is considered best practice to use an after BR to update a related record, but this would require query of the journal table in order to find\copy the last 'update' as journal updates are not available via the 'previous' object.
But while a general guide, ServiceNow do use before BR's to update journal fields and I would use the same approach as it greatly simplifies the solution, however you need to be sure that you will not abort any insert\update and your journal update has run.
This filter should include some OOB examples
/sys_script_list.do?sysparm_query=scriptLIKEwork_notes%5EORscriptLIKEcomments%5Ewhen%3Dbefore&sysparm_view=