Submit catalog item via Inbound Action

booher04
Tera Guru

I'm trying to submit a catalog item(already created) through an inbound action script:

Type: New

Target Table: Request (sc_request)

Action Type: Record Action

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

        var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId);

        var item = cart.addItem('acfb58a73bec6e100d0f8c9c24e45aa0'); //Multifactor Authentication Compliance	

        cart.setVariable(item, 'email_subject', email.subject);
        cart.setVariable(item, 'email_body', email.body_text);
		gs.log('Test Subject: ' + email.subject);
		gs.log('Test Body: ' + email.email_body_text);

        var rc = cart.placeOrder();

var grRITM = new GlideRecord('sc_req_item');
	
	grRITM.addQuery('request',rc.getValue('sys_id'));
	grRITM.query();
	
	if(grRITM.next()) {
			
		grRITM.setValue('sys_created_by', ' Inbound Email Action');
		grRITM.setValue('contact_type', 'email');
		grRITM.setValue('short_description', 'Multifactor Authentication Compliance' + ' - ' + email.subject);
		grRITM.setValue('description', 'Text from Email' + ' - ' + email.body_text);
		//Add Attachment(s)
		
		GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sc_req_item', grRITM.sys_id);
				
		grRITM.update();
				
		var emailGR = new GlideRecord("sys_email");
		emailGR.addQuery("sys_id", sys_email.sys_id);
		emailGR.query();
		if(emailGR.next()){
			emailGR.instance = grRITM.sys_id;
			emailGR.target_table = "sc_req_item";
			emailGR.update();
					
		}
			}
		})

This created a Request record but does not create an RITM.  If I switch the Target Table to sc_req_item, it creates an RITM but does not associate with a catalog item.  It's a blank RITM with no information. 

1 ACCEPTED SOLUTION

@Ankur Bawiskar the script I originally posted actually works, the issue was during my testing I was not adding the user email from my inbound action criteria into the test email within ServiceNow.  

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@booher04 

the Cart API should create both REQ and RITM

Did you try that script in background script?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@booher04 

another way is to use flow and check these links

Create RITM through inbound action by parsing mail body 

https://www.servicenow.com/community/itsm-forum/creating-ritm-using-inbound-action-and-cart-api/m-p/...

https://pathwayscg.com/scripting-for-the-servicenow-cart/

Submit and close a catalog item request from inbound email  -> response from Amit

AnkurBawiskar_0-1743774820078.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Yes, that's what I thought it would do as well if I set the table to sc_request, but it is not.  I also double checked the sys_id of that catalog item thinking that could be the issue. 

 

We do not use flow designer here so that won't work for us. 

 

Ran as background script and it did not work either. 

@booher04 

then it's not an issue with inbound table type REQ or RITM

If it works in background script then it will work in inbound action as well

Is there any user criteria applied on that catalog item?

share the background script here

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader