
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 02:31 PM
Hi Team,
I have a requirement to get the IP address (remote_ip) from the Transaction Log Entry and display it to a field in User profile.
I want to get this value from Transaction Log Entry - IP Address (remote_ip)
and display it on IP address (u_ip_address) field in my User profile
I tried creating a After - Update Business rule and assigned it to User Table then I used this script
current.u_ip_address = gs.getSession().getClientIP().toString();
current.update();
I also tried to create onChange Client Script using this script
var ipAddress = g_form.getSession().getClientIP().toString();
g_form.setDisplayValue('u_ip_address' , ipAddress);
Both of them did not work. I need some help to know what else to add on my script to make it work.
What should I add or remove on my script? If you could help with the scripting that would be a big help.
Your answer on this will be much appreciated, Thank you in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2020 10:06 AM
I think I got it and it is more consistent. I add more to the encoded query and a sort so that we got the most recent log activity otherwise I was not getting the correct IP all the time.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('syslog_transaction');
gr.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^sys_created_by=' + current.user_name +
'^urlSTARTSWITH/home.do'); //added urlSTARTSWITH/home.do so limit the number of items brought back
gr.orderByDesc('sys_created_on'); //Added sort so that the newest ones are at the top
gr.setLimit(1); //Set limit to 1 which should bring back the most recent log that matches the encoded query
gr.query();
if (gr.next()){
current.u_ip_address = gr.remote_ip;
current.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 02:36 PM
What table do you have your BR running on?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 03:13 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 03:23 PM
Running it there would not get anything. What conditions would it run under? Unless something was updated on the sys_user table the BR would never be triggered.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 03:30 PM
I changed it to Transaction Log Entry (syslog_transaction) and it works! However when other user logged in, the IP address on their profile did not update. Do they need to have transaction before that field to update?
Or
Is there a way that to get the IP address of current logged in user right after they logged in?