Insert record from one table to another table on update.

Maxwell3
Kilo Guru

Hello all,

I created a BR to update a custom field from the incident table to a field I created in the sys_journal_field table. The ultimate goal here is to print the additional comments and their respective priority level onto an email notification. Right now I am pulling from the Priority field on the incident table. The issue is that every time the additional comments are updated, the priority level will be different. I need a way to store the priority levels for each comment.

So, I decided to store the priority level from the incident table into a custom field I created in the sys_journal_field table.  The issue is that this BR creates a new record in the sys_journal_field table, it doesn't add the priority level into the additional comments. Here is what I have so far.

 

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord('sys_journal_field');
gr.initialize();
gr.u_new_priority=current.priority; //I need to store the priority into the u_new_priority
gr.insert();

})(current, previous);

 

The first snap shot is what I get. The second snapshot, is where the Priority level from the incident form should go.

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Manoj Kumar16
Giga Guru

Write an 'onBefore' ---> 'insert' business rule on the table sys_journal_field table

condtion--> current.name=='incident'

Add the below code to your business rule-

(function executeRule(current, previous /*null when async*/) {
var priority='';
var gr=new GlideRecord('incident');
gr.addQuery('sys_id', current.element_id);
gr.query();
if(gr.next())
{
priority=gr.priority;
}
current.u_new_priority=priority;
})(current, previous);

 

View solution in original post

3 REPLIES 3

Yogi3
Kilo Guru

you can business rule on SYS_JOURNAL_FIELD table using below script. It should be before business rule on insert.

 

var gr = new GlideRecord('incident');
gr.get(current.element_id);
current.setValue('u_new_priority',gr.priority);

 

 

find_real_file.png

find_real_file.png

 

Hope this helps!

Y

Manoj Kumar16
Giga Guru

Write an 'onBefore' ---> 'insert' business rule on the table sys_journal_field table

condtion--> current.name=='incident'

Add the below code to your business rule-

(function executeRule(current, previous /*null when async*/) {
var priority='';
var gr=new GlideRecord('incident');
gr.addQuery('sys_id', current.element_id);
gr.query();
if(gr.next())
{
priority=gr.priority;
}
current.u_new_priority=priority;
})(current, previous);

 

Thank you Manoj,

This worked but I had to make some adjustments.

I had to change,

from:

priority=gr.priority;

to:

priority=gr.getDisplayValue('priority');

Because only the numeric value was displayed, this fixed it.

Thank you again.