How to add specific user as requested for while submitting record via email

Samiksha2
Mega Sage

Hi All,

 

I am stuck in one code. I have created a inbound email action for creating request.

Users who are in user table and contact table for them request is creating but users who are not in the servicenow for them also request should create. 

For outside users, client wanted request should create and requested for should be specific user(example sysid- 12345).

var user = new GlideRecord('sys_user');
    user.addQuery('email', email.from);
    user.query(); //search contact table for user
    if (user.next()) {
        current.requested_for = user.sys_id;

    } else {
        current.requested_for = '12345'; //assign guest user
    }



    var cartID = GlideGuid.generate(null);
    var cart = new Cart(cartID);
    var item = cart.addItem('562790589388b11034dbbb2c5cba');
    cart.setVariable(item, 'short_description', email.subject);
    cart.setVariable(item, 'description', email.body_html);
    var rc = cart.placeOrder();

    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', rc.sys_id);
    ritm.query();
    if (ritm.next()) {
        ritm.short_description = email.subject;
        ritm.description = email.body_html;
        var users = new GlideRecord('sys_user');
        users.addQuery('email', email.from);
        users.query(); //search contact table for user
        if (users.next()) {
            ritm.requested_for = user.sys_id;

        } else {
            ritm.requested_for = '12345'; //assign guest user
        }
        ritm.update();
    }

 

Please help in this. 

 

Thanks,

Samiksha

2 REPLIES 2

Samiksha2
Mega Sage

I checked logs. Getting this error:

Root cause of JavaScriptException: com.glideapp.servicecatalog.exceptions.CartException
: com.glideapp.servicecatalog.exceptions.CartException: Your cart has item(s) no longer available.

Samiksha2
Mega Sage

my code was right. i forget to make Catalog available for any user