How to fill target in the sys_email record when we are creating RITM using Cart API?

hanaphouse
Giga Guru

We have this issue for awhile and want to know why the target field is not populated with this script and the attachments are not associated to the RITM?

I have the advanced inbound action script below:

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

    var cart = new Cart();
    cart.initialize();
    item = '3bc821e41b3f901021adfeeccd4bca6c';
    var ritm = cart.addItem(item);
    cart.setVariable(ritm, 'description', email.body_text);
    var screquest = cart.placeOrder();

})(current, event, email, logger, classifier);

Here's the result:

find_real_file.png

1 ACCEPTED SOLUTION

I believe the quantity is mandatory and is resulting in your NullPointer

'sysparm_quantity': '1',

View solution in original post

4 REPLIES 4

Kieran Anson
Kilo Patron

Hi,

As you're not using the "current" object, SN doesn't implicitly know what record you're wanting to set. You can set the target as below:

Note I've moved you to using the modern sn_sc.CartJS script as the Cart API is deprecated!

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

	var cart = new sn_sc.CartJS();
	var request =
		{
			'sysparm_id': '3bc821e41b3f901021adfeeccd4bca6c',
			'sysparm_quantity': '1',
			'variables':{
				'description': email.body_text,
			}
		};
	var cartDetails = cart.orderNow(request);
	//assuming two-step is off
	sys_email.instance = cartDetails.request_id;
	sys_email.table = "sc_request";

})(current, event, email, logger, classifier);

Tried running this modern cartJS() but it is returning an error:

find_real_file.png

Here's the error:

find_real_file.png

I believe the quantity is mandatory and is resulting in your NullPointer

'sysparm_quantity': '1',

Thank you. Looks good to me now - just had a minor change used sys_email.target_table instead of sys_email.table:

sys_email.instance = cartDetails.request_id;
sys_email.target_table = "sc_request";

 

My next question was how to get the RITM number instead of the REQ.