- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2014 01:11 PM
I was trying to create an Inbound Action where the senders are all part of the same group. The type needs to be forwarded. I have come up with an Action that will work with a list of users, which may be helpful to someone.
I was wondering how to create a condition that looks at the user who forwarded the email, checks their group, and if they are a member of a specific group, processes the inbound action. I have the order , and email processing order plugin sorted out, so I know when to stop processing the action. A also thought I could use the 'from:' field.
Maybe the answer is in my script, something like "from.group == "Service-Desk" {
Any suggestions welcome if someone has done this already. Here's what I have for specific users if anyone needs something similar. Many thanks, Mark S.
type=forward, co condition, uses validators.
gs.include('validators');
var from = gs.createUser(email.body.from);
//need more than one email address to work with validators
if (from == "john.doe@somewhere.com"||"james.doe@thisplace.com")
{
current.opened_by = from;
current.caller_id = email.from;
current.assignment_group = "sys_id of assignment group here";
current.assigned_to = email.from;
current.state = 1;
current.contact_type = "email";
current.short_description = email.subject;
current.description = "Email received from: " + email.origemail + "\n" + "Email copied to: " + email.to + "\n" + "Subject: " + email.subject + "\n\n" + email.body_text;
//send to log user who forwarded email.
gs.log("***Inbound Action from " + email.body.from);
event.state="stop_processing";
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2014 08:36 PM
This may look convoluted, but set this as your condition:
gs.getUser(). ÂgetUserByID( Âsys_email.getValue("user_id")). ÂisMemberOf( Â"GroupName")
It creates a user object [gs.getUser()], fetches the user record for the user that sent the email [ ÂgetUserByID( Âsys_email.getValue("user_id"))] and checks to see if the user is a member of a particular group [ ÂisMemberOf( Â"GroupName")]. "sys_email" is a GlideRecord of the email that is being processed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2014 01:18 PM
Hi Mark,
You can achieve it simply by adding a condition in your inbound email action like
email.from.indexOf("group_name") !-1
But it will run only in case of mails sent on behalf of group.
Alternatively, you can use a glide record query to check if the user is a member of a particular group/groups.
Here's a thread discussing same : how to see if updated by is member of a group
Thanks,
Mandar
EDIT : You can also use the isMemberOf( Â'group_name') functionality provided by service now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2014 11:08 AM
Thanks Mandar, I read up some more on the wiki, and the consensus seems to be 'why not just use 'isMemberOf' as you said.
This is the error I am getting.
org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in <refname> at line 6
3:
4: var from = gs.createUser(email.body.from);
5: gs.log("***Inbound Action from - " + email.body.from);
==> 6: if (from.isMemberOf('ServiceNow Administrators'||'IT - ServiceNow Support')){
7:
my script is:
s.include('validators');
//var from = email.from;
var from = gs.createUser(email.body.from);
gs.log("***Inbound Action from - " + email.body.from);
if (from.isMemberOf('ServiceNow Administrators'||'IT - ServiceNow Support')){
current.assignment_group = "33194bd90a0a3ce00100f0f13b5f845e";
current.assigned_to = email.from;
current.state = 1;
current.contact_type = "email";
current.short_description = email.subject;
current.insert();
event.state="stop_processing";
}
Once again, many thanks for your help. Mark

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2014 11:20 AM
Hi Mark,
It seems that the from is not getting instantiated properly, (I'm not aware of gs.createUser() function)
you could try this code snippet to instantiate it.
var from = new GlideRecord("sys_user");
from.get("sys_id", email.body.from);
Let me know if it's helpful.
Thanks,
Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2014 11:30 AM
Hello Mark,
You can use isMemberof function as mention below:
var myUserObject = gs.getUser();
myUserObject = myUserObject. ÂgetUserByID( Â'abel.tuter'); //Pass sys_id or User Id
if( ÂmyUserObject. ÂisMemberOf( Â'ServiceNow Administrators') || ÂmyUserObject. ÂisMemberOf( Â'IT - ServiceNow Support')){
//write require line of code
}
Please try and let me know the outcome
Regards,
Solutioner