Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Create Requested Item with all variables from Inbound Action

Samiksha2
Mega Sage

Hi All,

 

I have a requirement to create Requested Item with all the variables from Inbound Action.

Catalog form name: Generic Request

Variables- Requested for -(referring to sys_user)

Email- Autopopulate based on Requested for

Account - lookup select box(refer to customer_account)

Client - lookup select box(refer to customer_account, name= Id. I have added reference qualifier. based on account Id will show)

Short description- Single text line

Description- HTML text

 

I have created Inbound action on sc_request table( I take help from this community link https://www.servicenow.com/community/developer-forum/create-requested-item-from-inbound-action-with-... )

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    var user = new GlideRecord('customer_contact');
    user.addQuery('email', email.from.toLowerCase());
    user.query(); //search contact table for user
    if (user.next()) {
        var requested_for = user.sys_id;
        if (user.account) { 
            var account = user.account.getDisplayValue();
            var account_id = new GlideRecord('customer_account');
            account_id.addEncodedQuery('name=' + account);
            account_id.query();
            if (account_id.next()) {
                var client = account_id.u_client.getDisplayValue();
            }
        } else {
            //do nothing
        }
    }
    var cartID = GlideGuid.generate(null);
    var cart = new Cart(cartID);
    var item = cart.addItem('562790589388b11034dbbb2c5cbu1908');
    cart.setVariable(item, 'account_hidden', account);
    cart.setVariable(item, 'client', client);
    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.getValue('sys_id'));
    ritm.query();
    if (ritm.next()) {
        ritm.short_description = email.subject;
        ritm.description = email.body_html;
        ritm.comments = email.body_text;
        ritm.requested_for = gs.getUserID();
        ritm.contact_type = "email";
        ritm.update();
    }
})(current, event, email, logger, classifier);

 I am only receiving the mail. Request , requested item nothing is generating. 

Please help in this.

 

Thanks,

Samiksha

10 REPLIES 10

Mohith Devatte
Tera Sage

Hello @Samiksha2 try Cart JS instead of Cart 

eXAMPLE CODE :

var cart = new sn_sc.CartJS();
var item = { // Note that values using CartJS are instantiated via a JSON object
	'sysparm_id': '060f3afa3731300054b6a3549dbe5d3e', // REPLACE SYS_ID OF CATALOG ITEM
	'sysparm_quantity': '1',
	'variables': {
		'ram': '16',
		'os': 'win10',
		'storage': '1tb'
	}
};
var cartVals = cart.addToCart(item); // The addToCart function returns a JSON object reflecting the status of the cart
var checkoutVals = cart.checkoutCart(); // The checkoutCart function returns a JSON object with info about the submitted cart, contents varying if two-step checkout is active

 

HOPE THIS HELPS 

MARK MY NASWER CORRECT IF THIS HELPS YOU 

ThANKS

Hi @Mohith Devatte ,

 

I have one doubt. Cart Option is disable in my instance. Will it work?

@Samiksha2 it should work i guess not sure but worth giving it a shot .if it works let me know

Hi @Mohith Devatte,

No it is not working.

var cart = new sn_sc.CartJS();
var item = { // Note that values using CartJS are instantiated via a JSON object
'sysparm_id': '562790589388b11034dbbb2c5cbu1908', // REPLACE SYS_ID OF CATALOG ITEM
'sysparm_quantity': '1',
'variables': {
'short_description': email.subject,
'description': email.body_html,

}
};
var cartVals = cart.addToCart(item);
var checkoutVals = cart.checkoutCart();