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

Chander Bhusha1
Tera Guru

Hi Aki,

 

This can be achieved using before update as you want the update on the sysevent table only so the code would be:

Make sure that the username is correct field backedn name as its custom field so its backend field would be --- u_user_name

Condition would be --- before insert/update

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

}

 

 

Please mark helpful and correct.

Thanks,

CB

Hello CB,

Thank you for your reply. I changed "after" to "before", but the BR still didn't work properly...

Hi Aki,

Can you condition as putting the log message inside the BR and check its running or not. 

And one more thing is the filter condition is correct and can you validate as well.

Below is the script to check for logs.

(function executeRule(current, previous /*null when async*/) {
gs.log('@inside BR '+ current.user_name);
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;
gs.log('@inside loop '+current.u_ip_address_from_transaction_log);
}

And check if you are getting both the logs and share the output of these.

Logs message can be found in system logs -- All and search with message.

as shown in the screenshot.

find_real_file.png

 

And search with message contains the string

IF both the logs are not comings it means the BR is not running so try changing the filter condition.

 

Thanks,

CB

Hi CB,

After removing Filter Conditions, I got the log below.

It looks like "current.user_name" is not resolved. Could you check why it's not resolved and why the Filter Conditions prevented BR from being run?

The Filter Conditions ([Name] is [attachment.read]) is met as the following screen shot of Event record created.

*[user_name] field is a default field in [syslog_transaction] table.

find_real_file.png

find_real_file.png