Inbound Action from specific group

Baggies
Kilo Guru


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";
}

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

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.


View solution in original post

9 REPLIES 9

ohhgr
Kilo Sage
Kilo Sage

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.


Baggies
Kilo Guru

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




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


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