Inbound Action to create Request & Requested Item failed

MWright1
Giga Guru

Getting this in the Email log:

Create Video Conferencing Req (forward) : did not create or update sc_req_item using current

 

This is my Inbound Action:

createRequest();

function createRequest() {
    var user_sys_id = gs.getUserID();
    var comments = email.body_text;
    var subject = email.subject;
    var body = email.body_html;
    var cart = new Cart(); //calling the cart API
    var item = cart.addItem('0520833f1b4fc2902bea0fa4cc4bcb92'); //sys_id of the catalog item I want to fire

    cart.setVariable(item, 'short_description', subject ); //sets catalog variable to the email's subject
    cart.setVariable(item, 'comments', body); //sets catalog variable to email's body

    var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object. 
    updateRITM(rc.sys_id, body, comments); //call a function immediately to update the ritm.   
}

function updateRITM(req, body, comments, subject) {
    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', req); 
    ritm.query();

    while (ritm.next()) {
        ritm.comments = comments;
        ritm.short_description = subject;

        ritm.assignment_group = '9a1540151b97ce106d0c33b4cc4bcb16';
        ritm.update();
    }

}

 

The Catalog Item has Any User as Available for which allows anyone to create.  I don't know what else I am missing.  Please help.

 

Thanks,

M

 

 

 

5 REPLIES 5

Rajesh Chopade1
Mega Sage

Hi @MWright1 

I would suggest add .sleep() before calling the update function. Might be record creation not happen when update function is running.

// Wait for the order to be processed before updating the RITM
    gs.sleep(2000);

    updateRITM(rc.sys_id, subject, comments);

 

One more observation about your code, you passing 3 parameters to update function but actual update function having 4 parameters.

 

i hope my answer helps you to resolve your issue, it yes please mark my answer helpful & correct.

thank you

rajesh

Thanks for the catch on the parameters.  Missed that.  

Upon further investigation, if I manually forward the email - go to Video Conference mailbox in outlook and manually click forward the email to ServiceNow - the inbound action works.

 

However, it I send an email to Video Conference from my own inbox (there is a rule to forward the email to ServiceNow), the inbound action would trigger and then fail to create the RITM.

 

I don't understand the difference.  

Here i would suggest to print the log (subject, sender, body) and check difference from both email.

I think difference in email body and header structure. 

Automatically forwarded emails might include prefixes like "FW:"