Inbound Email Action - Retrieve User through script

Not applicable

Hi,
In my test application, I am using Inbound Email Action Script for creating Change Request. I am populating all mandatory fields of Change Request.
I want to populate Requested By & Original Requester fields from the Inbound Script.
I tried searching existing users/created new user for my test company..but still I am not able to search that user through script.
Can anyone please guide me on how to search User through script.
I also tried below script for getting current logged in user & setting this to Requested By field in Inbound script, but it is now working
var myUserObject = gs.getUser();
myUserObject.getFullName() ;
As a work around I have hard coded my user's sys_id to Requested By field..I don't want to hardcode any values in my code..
Can u please guide me on getting this functionality work

Thanks in advance.
Regards,
Piyush Divecha

4 REPLIES 4

adiddigi
Tera Guru

So you mean to say, You have to populate the 'requested by' and 'originally requested for' by the person who sent the email?
Firstly you need to have that user in the database,if not should you create it?
Glide the user table to find if the user is already in sys_user table. If he is there, then use his sys_id to populate the requested for
Code will look something like this



var gr = new GlideRecord('sys_user');
gr.addQuery('name',email.from);
gr.query();
if(gr.next()){
current.requested_for = gr.sy_id; (you can instead use the display value too xD)
}
else{
//If you need to create the user and then use him
var sid = gs.createUser(email.from);
var sid = gs.getUserID();

//sid will have the userID.
}

http://wiki.service-now.com/index.php?title=Inbound_Email_Actions

check this link out !


Not applicable

Hi,
Thanks for reply.
Actually I had earlier tried searching User through the script mentioned by you. Still I am not able to search User.
This is what I have done but getting no results. User is saved in sys_user table. Is there is any rights related issue?
var gr = new GlideRecord('sys_user');
gr.addQuery('name','Piyush Divecha');
gr.query();

I have tried searching user by other fields like email but still no results. Can u guide me on this.

Regards,
Piyush Divecha


I suggest you get the sys_id of your record and try searching using it. and check whether your name is in 'sys_user' table

Hope this helps

Cheers


Not applicable

Hi,
Now I am able to search User. Actually while creating email I was not putting value in User field..as a result email from was blank..so it was not able to search User.
Thanks for your comments.

Regards,
Piyush Divecha