Need help with business rule for sys_email table

mooreka777
Giga Contributor

Hello There!

I need some help and hopefully you can point me in the right direction.   I have a requirement to create all users for an incoming email.   The   unknown user can be a sender, recipient, cc, bcc, etc.   What I would like to do is write a business rule that does the following:

creates the sender in the sys_user table;

creates all of the users in the to, cc, bcc fields ;

changes the email.userid from undefined, or guest, to the newly created user

The code below is just for testing, but it gives an example (all-be-it poor) example of what I am trying to do.

These are static entries so I can debug better:

var email = '0eb4193bdb757640a66af1fcbf9619a5';

var current = new GlideRecord('sys_email') ;

var u_sysid = current.user_id ; // user_id is a reference to sys_user !!

var u_sysid = current.user ; // user_id is a reference to sys_user !!

var u_uid = current.uid ; // user_id is a reference to sys_user !!

debug = 1;

var check= (current.get(email)) ;

if (u_uid) {

gs.info('current uid: ' + u_uid);

}

// check if the email.user exist

var uname = new GlideRecord('sys_user') ;

uname.addQuery('sys_id',u_sysid);

uname.query();

//

if (debug) gs.info('current uname: ' + uname.query());

var gr = new GlideRecord('sys_user');

// gr.addQuery('u_aup', true);

gr.addQuery('user', current.user);

gr.query();

if (debug) {

gs.info('Current.get.email: ' + check);

gs.info('current u_sysid: ' + u_sysid);

gs.info('current user: ' + current.user.toLowerCase());

gs.info('current userid: ' + current.user_id.toLowerCase());

gs.info('current recipients: ' + current.recipients.toLowerCase()) ;

gs.info('current bcc: ' + current.blind_copied.toLowerCase()) ; // if undefined create user

gs.info('current cc: ' + current.copied.toLowerCase()) ; // instance

gs.info('current sys_email: ' + current.sys_email());

// if(!current.user_id) {

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', current.user.toLowerCase());

gr.query();

gs.info('current gs.query: ' + gr.query());

}

-----------------------------------------------------

////

// Script Output

////

What I am trying to do is update the current.userid with the current.user AFTER the user is created.

*** Script: current uname: undefined

*** Script: Current.get.email: true

*** Script: current u_sysid: undefined

*** Script: current user: asdf@gmail.com

*** Script: current userid: undefined

*** Script: current recipients: asdfasdf@gmail.com; asdf@asdf.com

*** Script: current bcc: undefined

*** Script: current cc: undefined

*** Script: current sys_email: undefined

*** Script: current gs.query: undefined

-----------------------------------------------------

Thanks for any help, guidance, or examples you can provide.   I am stuck!  

Kindly,

Kelly

3 REPLIES 3

Dave Smith1
ServiceNow Employee
ServiceNow Employee

Are you looking for ways of creating a new user via an incoming email?


Hello Dave!



Thanks for the help.  



I am looking to move the user creation process for emails into a business rule.  



Thanks,


Kelly


Okay... I've not had much experience with inbound email rules, but everything looks fine up there - just that it seems not to be extracting information from the email.. is that correct?