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

Pedro Lopez
Kilo Guru

Hi Bernard,

The script seems to be fine, just try this to validate it properly:

  • Run your script in "Script - Background" - Validate if the REQ/RITM are created properly.
  • Remove the table name from your Inbound Action - The script is creating the REQ/RITM automatically.

Workaround: If it is not working from an Inbound Action, try it by using a Business Rule. The inbound action will insert the record, this will help you to trigger your business rule. 

 

Hope this helps,

Pedro

Michael Fry1
Kilo Patron

The inbound action should be on the request table.

The type should be New, not Record Action.

 

Hi Michael,

Thanks for your reply, I have tried it on the Request [sc_request] table as well and get the same issue I'm afraid.

Also yes, the Type = New but I was referring to the Action type = Record Action, see screenshots below:

find_real_file.png

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();
        }