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-16-2020 01:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 10:06 AM
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?