How can we get the session IP address in Script action ? getclientip() is not working in script action

Rashmi Shetty
Kilo Explorer

I want to get the ip address of the user session who triggered the event . Since i am using the OOB event, i have to get this data in script action. But i am unable to use the gs.getsesion().getClientIp() method and get the correct result. Please help me to get this done.

2 REPLIES 2

Jace Benson
Mega Sage

Are you getting any result using the following code;

var session = gs.getSession();
var addr = session.getClientIP();
gs.addInfoMessage(addr);

oh, in a script action, yea, that is not going to work as script action's run after the event is processed.

You'd have to modify the event to pass in the ip address on the generation of the event.

So I'm not sure what event you're triggering but for the sake of showing you what I mean, lets take...

gs.eventQueue("incident.commented", current, gs.getUserID(), gs.getUserName());

Into account.

You'd have to find aynthing using the event parm2, and then use JSON to send in multiple details with some code modification like so;

var session = gs.getSession();
var details = {
  ip: session.getClientIP(),
  username: gs.getUserName()
};
gs.eventQueue("incident.commented", current, gs.getUserID(), JSON.stringify(details));

Then in the script action you'd have to parse the parm2 back into an object.