Business Rule to retrieve value from another table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 11:31 PM
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)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 11:44 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 12:06 AM
Hello CB,
Thank you for your reply. I changed "after" to "before", but the BR still didn't work properly...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 12:11 AM
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 12:49 AM
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.