The CreatorCon Call for Content is officially open! Get started here.

Business Rule to retrieve value from another table.

Aki17
Kilo Guru

I need a Business Rule to retrieve value from another table. The 2 tables are:


[syslog_transaction] table
- user_name: UserA
- remote_ip: 10.1.2.3

and
[sysevent] table
- sys_created_by: UserA
- u_ip_address_from_transaction_log(should be auto-populated using BR by referencing "remote_ip" in  [syslog_transaction] table)


After a record is created in [sysevent] table, the custom field "u_ip_address_from_transaction_log" should be auto-populated by referencing "remote_ip" field in [syslog_transaction] table which has same user name. (Please see the image below)

find_real_file.png

 

For this requirements, I wrote the following BR, but it didn't work and the custom field was not populated. Please kindly check where the problem is.

*after insert/update BR in [sysevent] table:

(function executeRule(current, previous /*null when async*/) {
var gr=new GlideRecord("syslog_transaction");
 gr.addQuery("sys_created_by",current.user_name);
 gr.query();
if(gr.next()){
	current.u_ip_address_from_transaction_log = gr.remote_ip;
	gr.update();
}
})(current, previous);

*Filter Conditions is "[Name] is [attachment.read]"

 

Best Regards,
Aki

34 REPLIES 34

So in the field the value is present or not .

And can you check in the list layout if the value is present in the username field or not.

It seems that field is populated in the database.

 

Hi CB,

The user_name field has the value of logged in user name as below. So I don't understand why the log doesn't have user name..

find_real_file.png

 

Hi Aki,

Can you try putting the value of username in current.getValue('') function as shown below:

AFter BR code:

(function executeRule(current, previous /*null when async*/) {
gs.log('@inside BR '+ current.getValue('user_name'));
var gr=new GlideRecord("syslog_transaction");
 gr.addQuery("sys_created_by",current.getValue('user_name'));
 gr.query();
if(gr.next()){
gs.log('@inside loop '+gr.remote_ip);
	current.setValue('u_ip_address_from_transaction_log',gr.remote_ip);
current.update();

}

And I can see that the created by field is also holding the same value so can try putting the current against sys_created_by

If you want before BR code then use script from the first reply from myside.

Hi CB,

I tried that script and the Log got changed as below:

The Log message got to have "null", which should have "20200615"..

find_real_file.png

Hi CB,

Also, when I "manually" created a record in [sysevent] table, the "u_ip_address_from_transaction_log" field got populated automatically!

However, when the Event record gets inserted by API by downloading an attachment in KB article, that field was not populated...

Could you give me a possible solution for this, please?