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

asifnoor
Kilo Patron

Hello Aki,

Let us add few logs and check first if your Br is executing or not. I am not sure if the entry is inserted into transaction by the time this BR is executed.

(function executeRule(current, previous /*null when async*/) {
var gr=new GlideRecord("syslog_transaction");
gs.log("Current user name is "+current.user_name);
 gr.addQuery("sys_created_by",current.user_name);
 gr.query();
if(gr.next()){
gs.log("Entered into your if condition"+gr.remote_ip);
	current.u_ip_address_from_transaction_log = gr.remote_ip;
	gr.update();
}
})(current, previous);

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

 
 

Hello asifnoor,

Thank you for your advice. I temporarily changed the BR to what you gave me here, but could you tell me where I can check the log to confirm if the BR ran successfully or not?

Hi,

In your left navigation -> System logs -> All

There add a filter to run by last 15 mins and sort by created desc order and check it. 

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

Hi asifnoor,

It seems I got the Log below, but it looks like "user_name" is not resolved.

find_real_file.png

So as per logs, username is empty. So check if the username column is having any value or not in that table.