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

Hi asifnoor,

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 

 

Hello Aki,

Is your BR written on sysevent table or transaction?

Can you share the complete BR screenshot which shows conditions, tablename and the code.

This should help us to debug the issue faster.

Mark the comment as helpful if it helps to debug the issue.

Regards,
Asif
2020 ServiceNow Community MVP

Hi asifnoor,

Here is the screenshot of the BR. Please kindly check it.

find_real_file.png

find_real_file.png

Hi,

did you check if it is populated during insert?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

Also since it is after update you need to use current.update() instead of gr.update()

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader