Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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 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.  

@booher04 

Glad to know.

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