help with Business role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 01:33 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 01:49 PM
Hi there @Arthur Sanchez
ou need to create Business Rules that handle the journal entries whenever they are added. For this, you should focus on the sys_journal_field table, which stores journal entries (such as comments) for all records. You can create separate Business Rules for each table to handle the insertion and updating of journal entries.
Create a Business Rule for x_1316384_terca_problema:
(function executeRule(current, previous /*null when async*/) {
var problemaRecord = new GlideRecord('x_1316384_terca_problema');
if (problemaRecord.get(current.element_id)) {
var responseRecord = new GlideRecord('x_1316384_terca_resposta');
responseRecord.addQuery('number', problemaRecord.number);
responseRecord.query();
if (responseRecord.next()) {
var newJournalEntry = new GlideRecord('sys_journal_field');
newJournalEntry.initialize();
newJournalEntry.element_id = responseRecord.sys_id;
newJournalEntry.element = 'comments';
newJournalEntry.value = current.value;
newJournalEntry.insert();
}
}
})(current, previous);
Create a Business Rule for x_1316384_terca_resposta:
(function executeRule(current, previous /*null when async*/) {
var respostaRecord = new GlideRecord('x_1316384_terca_resposta');
if (respostaRecord.get(current.element_id)) {
var problemaRecord = new GlideRecord('x_1316384_terca_problema');
problemaRecord.addQuery('number', respostaRecord.number);
problemaRecord.query();
if (problemaRecord.next()) {
var newJournalEntry = new GlideRecord('sys_journal_field');
newJournalEntry.initialize();
newJournalEntry.element_id = problemaRecord.sys_id;
newJournalEntry.element = 'comments';
newJournalEntry.value = current.value;
newJournalEntry.insert();
}
}
})(current, previous);
If this helps kindly accept the answer thanks ,much.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 06:11 AM - edited 05-22-2024 06:11 AM
I'm trying to run your code in 2 different business roles but nothing works, can you tell me what configuration of your BR you used?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 07:16 AM
Hey @Arthur Sanchez
Can you try commenting out the number and add something else, any other field in it's place as a test?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 10:45 AM