Anyone know why inbound results in: did not create or update incident using current

ElC
Tera Contributor

I am trying to reopen an incident from email but the inbound always results in error:  Service Desk - Reopen incident : did not create or update incident using current

 

Here is the script:

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Check if the record is an incident
if (current.getTableName() == "incident") {
 
gs.info('Processing inbound action for incident record: ' + current.number);

// Check if the incident is in resolved state (state 6)
if (current.state == 6) {
gs.info('Incident ' + current.number + ' is in resolved state.');

// Check if the email subject contains "reopen"
var subject = email.subject.toLowerCase(); // Assuming email.subject is accessible
if (subject.indexOf("reopen") >= 0 || subject.indexOf("wieder geöffnet") >= 0) {
gs.info('Attempting to reopen incident ' + current.number);

// Process legitimate reopen request
current.state = 12; // Set state to reopened '12' is the state code for reopened
current.work_notes = 'The caller requested to reopen the incident.';
current.comments = "Email reply from: " + email.origemail + "\n\n" + email.body_text;
} else {
gs.info('Email does not request to reopen incident ' + current.number);

// Handle attempted reopen on a closed incident
if (current.state == 7) {
gs.info('Incident ' + current.number + ' is closed. Cannot reopen.');
gs.eventQueue("incident.closed.noreopen", current, current.state, previous.state); // event and parameters as needed
current.comments = 'User attempted to re-open this incident. Notification sent to user; incident may not be re-opened.';
}
}
} else {
gs.info('Incident ' + current.number + ' is not in resolved state. Skipping reopen check.');
}
} else {
gs.info('Inbound action skipped for non-incident record.');
}
})(current, event, email, logger, classifier);
 
All suggestions appreciated.
2 ACCEPTED SOLUTIONS

Swapnil24
Giga Guru

Hi @ElC, I think you are missing the update function call in your script.

current.update();

 

Thank you,

Swapnil Deo

 

View solution in original post

Community Alums
Not applicable

Hi @ElC ,

The only issue I can see is that you are not updating the data anywhere, please find the updated script-

 

(function runAction(current, event, email, logger, classifier) {
    if (current.getTableName() == "incident") {
        gs.info('Processing inbound action for incident record: ' + current.number);
        if (current.state == 6) {
            gs.info('Incident ' + current.number + ' is in resolved state.');
            var subject = email.subject.toLowerCase();
            if (subject.indexOf("reopen") >= 0 || subject.indexOf("wieder geöffnet") >= 0) {
                gs.info('Attempting to reopen incident ' + current.number);
                current.state = 12;
                current.work_notes = 'The caller requested to reopen the incident.';
                current.comments = "Email reply from: " + email.origemail + "\n\n" + email.body_text;
                current.update();
            } else {
                gs.info('Email does not request to reopen incident ' + current.number);
                if (current.state == 7) {
                    gs.info('Incident ' + current.number + ' is closed. Cannot reopen.');
                    gs.eventQueue("incident.closed.noreopen", current, current.state, previous.state);
                    current.comments = 'User attempted to re-open this incident. Notification sent to user; incident may not be re-opened.';
                    current.update();
                }
            }
        } else {
            gs.info('Incident ' + current.number + ' is not in resolved state. Skipping reopen check.');
        }
    } else {
        gs.info('Inbound action skipped for non-incident record.');
    }
})(current, event, email, logger, classifier);

 

current.update(); //its required to save the data

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

 

View solution in original post

4 REPLIES 4

Swapnil24
Giga Guru

Hi @ElC, I think you are missing the update function call in your script.

current.update();

 

Thank you,

Swapnil Deo

 

Community Alums
Not applicable

Hi @ElC ,

The only issue I can see is that you are not updating the data anywhere, please find the updated script-

 

(function runAction(current, event, email, logger, classifier) {
    if (current.getTableName() == "incident") {
        gs.info('Processing inbound action for incident record: ' + current.number);
        if (current.state == 6) {
            gs.info('Incident ' + current.number + ' is in resolved state.');
            var subject = email.subject.toLowerCase();
            if (subject.indexOf("reopen") >= 0 || subject.indexOf("wieder geöffnet") >= 0) {
                gs.info('Attempting to reopen incident ' + current.number);
                current.state = 12;
                current.work_notes = 'The caller requested to reopen the incident.';
                current.comments = "Email reply from: " + email.origemail + "\n\n" + email.body_text;
                current.update();
            } else {
                gs.info('Email does not request to reopen incident ' + current.number);
                if (current.state == 7) {
                    gs.info('Incident ' + current.number + ' is closed. Cannot reopen.');
                    gs.eventQueue("incident.closed.noreopen", current, current.state, previous.state);
                    current.comments = 'User attempted to re-open this incident. Notification sent to user; incident may not be re-opened.';
                    current.update();
                }
            }
        } else {
            gs.info('Incident ' + current.number + ' is not in resolved state. Skipping reopen check.');
        }
    } else {
        gs.info('Inbound action skipped for non-incident record.');
    }
})(current, event, email, logger, classifier);

 

current.update(); //its required to save the data

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

 

I have added current.update() but its still not reopening the incident and I get the same error message.

Any other thought what could be the issue here? 

ElC
Tera Contributor

Ignore above comment from me its working fine now. Can't believe I missed update