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'
1 REPLY 1

Tony Chatfield1
Kilo Patron

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=