inbound email action Scoped Application

Harish KM
Kilo Patron
Kilo Patron

I have created an inbound email action which is in scoped application.

here the problem is If I glide record user table to check and set the user as "guest". it doesnot create the record. it jus skips the inbound email action.

Here is the code.

current.short_description = email.subject; // Set email subject

current.description = email.body_text; // set email body

var eto = email.to.toLowerCase().toString();

var sid='';

var rec = new GlideRecord('sys_user');

rec.addQuery('email',email.from);

rec.query();

if(rec.next()){

  gs.log("inside");

  sid = rec.sys_id.toString();

  gs.log("user is"+sid);

}

  if(sid=='')

    {

    gs.log("else");

      sid = gs.getUser().getUserByID('guest').getID();

    gs.log("user is"+sid);

    }

current.u_caller = sid;

  current.insert();

NOTE: If i use same code for global application. it does work . I am not sure why it is not working for scoped application.

Can any one sort this out?

Regards
Harish
1 ACCEPTED SOLUTION

As noted earlier, gs.log() is not available in scoped applications. Please use the scoped debugging methods in scoped scripts.



Scoped Script Logging - ServiceNow Wiki


View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

I suspect your gs.getUser() may be having issues in the scoped app. Try this in place of the line sid = gs.getUser()...



var user = new GlideRecord('sys_user');


user.get('user_name', guest);


sid = user.getValue('sys_id');



Also, note that gs.log() is not supported in scoped apps. Use gs.info(), gs.debug(), gs.warn(), and gs.error().


Still no luck. It doesnot create record even when the user is present in the database



Updated Code:


// Implement email action here


current.short_description = email.subject; // Set email subject


current.description = email.body_text; // set email body


var eto = email.to.toLowerCase().toString();


  gs.log("Inbound run1"+eto);


var sid='';


var rec = new GlideRecord('sys_user');


rec.addQuery('email',email.from);


rec.query();


if(rec.next()){


  gs.log("inside");


  sid = rec.sys_id.toString();


  gs.log("user is"+sid);


}


  if(sid=='')


    {


    gs.log("else");


    var user = new GlideRecord('sys_user');


user.get('user_name', guest);


sid = user.getValue('sys_id');


    gs.log("user is"+sid);


    }


current.requestor = sid;


  current.insert();


Regards
Harish

Hi ctomasi



Earlier I was using the below code


current.short_description = email.subject; // Set email subject


current.description = email.body_text; // set email body


current.u_requestor = email.from; // set email caller


current.state = 1; // set state to new


current.contact_type = "email"; // set channel to email


current.priority = 4; // set priority to low


current.company = gs.getUser().getCompanyID();// Set company


current.insert();



The above code is working fine. Now If any user sends the email to servicenow who are not present in the database I need to set the caller field as "guest". Could you let me know how to do this as I am facing issues


Regards
Harish

Hi Harish,



i hope,


      if user is not available in servicenow database, servicenow will consider user as guest( out of the box).