Submitting a catalog item from an Inbound Action

Bernard Angeles
Giga Contributor

Hi all,

I have been tasked with triggering the submission of a catalog item when an email is received.

I don't have much of a coding background so I'm sure the problem is somewhere or something to do with my code...

Here is my current inbound action below:

Target table: sc_req_item

Action type: Record Action

Script:

createRequest();

function createRequest() {
	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	
	var item = cart.addItem('65fcbfee75642400af0e5269def2e168');
	
	cart.setVariable(item, 'sn_req_app', '1');
	cart.setVariable(item, 'sn_req_details', 'Sample text');
	
	var rc = cart.placeOrder();
}

A few other points:

  • There are no field actions, just the above script
  • I have ensured that in my email submission tests, the condition to trigger the inbound action is correct
  • The sys_id is pointing to an active test catalog item with only 2 variables both of which are non-mandatory
  • Global scope

 

What I have found is, when the email is received, I get the following mesage in the email log: "Information - Skipping 'inbound_action_name', did not create or update sc_req_item"

In testing I have also noticed that if I place a field action along with the script (for example, Short Description - From email - Subject) it will generate a blank RITM record with no Item attached.

 

Any help on this would be much appreciated!

Thank you,

Bernard  

 

1 ACCEPTED SOLUTION

That is all correct. Target table should be Request.

Change your script to look like this:

(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('65fcbfee75642400af0e5269def2e168');

        cart.setVariable(item, 'sn_req_app', '1');
        cart.setVariable(item, 'sn_req_details', 'Sample text');

        var rc = cart.placeOrder();

        var ritmRec = new GlideRecord("sc_req_item");
        ritmRec.addQuery("request", rc.sys_id);
        ritmRec.query();
        if (ritmRec.next()) {
            ritmRec.short_description = email.subject.toString();
            ritmRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
            ritmRec.contact_type = "email";
            ritmRec.update();
        }
        //update target in email table, as it won't be updated as the record was inserted through cart API
        if (rc != '') {
            var email_rec = new GlideRecord('sys_email');
            email_rec.get(sys_email.sys_id);
            email_rec.instance = rc.sys_id;
            email_rec.target_table = "sc_request";
            email_rec.update();
        }

View solution in original post

15 REPLIES 15

Hi Michael, 

I have the same requirement to create REQ from email, I tried your script, and it worked, but for me 2 REQs are getting created, one attached to the email table without any RITM/SCTASK. One REQ with a RITM and SCTASK (maybe it's from the flow attached on the catalog item).  Is there any way to solve this.

 

Thanks,

Shruthi