help with Business role

Arthur Sanchez
Giga Guru

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);

 

in the options the fields: When - before  and update - check
The problem is, how do I take each journal input that the user puts in the record in table x_1316384_terca_problema and throw this same input into table x_1316384_terca_resposta?
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'

 
 
 
 
4 REPLIES 4

Its_Azar
Tera Guru

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.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

@Its_Azar 

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?

KevinBellardine
Kilo Sage

Hey @Arthur Sanchez  

Can you try commenting out the number and add something else, any other field in it's place as a test?

I can't bro, I have to use 'number' as a reference