Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Autoclose Case after copy to Incident

DIVIASSAS
Tera Contributor

Hi, 

i have a problem cause I prepared a button form the 'burger' List on Case form as You can See Below:

(DK INC)

DIVIASSAS_0-1704718992698.png

 

This button will copy all data from Case to new created Incident, and it's working properly.

I have a code but I want to also change the state of this 'Case' to resolved when user decide to copy ticket do Incident.

 

What should I add to the code and where ? 

 

function confirmCreateIncident() {

    var conf = confirm("Are you sure you want to CREATE INCIDENT?\n\n");
    if (conf == true) {
        gsftSubmit(null, g_form.getFormElement(), 'create_incident');
    } else
        return false;
}

if (typeof window == 'undefined')
    doCreateINC();

function doCreateINC() {
    var inc = new GlideRecord('incident');
    inc.initialize();
    var worknotes = current.work_notes.getJournalEntry(-1);
    var addcomments = current.comments.getJournalEntry(-1);

    // inc.number = getNextObjNumberPadded();
    // inc.assignment_group = current.assignment_group.getValue('sys_id');
    inc.assigned_to = current.assigned_to.getValue('sys_id');
    inc.short_description = [current.number] + ' - ' + current.short_description;
    inc.description = '[Transformed from ' + [current.number] + '] ' + "\n" + current.description;
    inc.work_notes = worknotes;
    inc.comments = addcomments;
    inc.caller_id = current.opened_by.getValue('sys_id');
    inc.contact_type = 'self-service';


    var incSuccess = inc.insert();
    if (incSuccess) {
        copyAttachment(inc, current.sys_id);
        action.setRedirectURL(inc);
    }
}

function copyAttachment(inc, recordID) {
    GlideSysAttachment.copy(current.sys_class_name, current.sys_id, inc.sys_class_name, inc.sys_id);
}

 

 

1 ACCEPTED SOLUTION

SanjivMeher
Mega Patron
Mega Patron

I would make few improvements to the script. I would also add the case id as parent in the incident. And then close the case

 

function confirmCreateIncident() {

    var conf = confirm("Are you sure you want to CREATE INCIDENT?\n\n");
    if (conf == true) {
        gsftSubmit(null, g_form.getFormElement(), 'create_incident');
    } else
        return false;
}

if (typeof window == 'undefined')
    doCreateINC();

function doCreateINC() {
    var inc = new GlideRecord('incident');
    inc.initialize();
    var worknotes = current.work_notes.getJournalEntry(-1);
    var addcomments = current.comments.getJournalEntry(-1);

    // inc.number = getNextObjNumberPadded();
    // inc.assignment_group = current.assignment_group.getValue('sys_id');
    inc.assigned_to = current.assigned_to.getValue('sys_id');
    inc.short_description = [current.number] + ' - ' + current.short_description;
    inc.description = '[Transformed from ' + [current.number] + '] ' + "\n" + current.description;
    inc.work_notes = worknotes;
    inc.comments = addcomments;
    inc.parent = current.getValue('sys_id');;
    inc.caller_id = current.opened_by.getValue('sys_id');
    inc.contact_type = 'self-service';


    var incSuccess = inc.insert();
    if (incSuccess) {
        copyAttachment(inc, current.sys_id);
        action.setRedirectURL(inc);
        current.state = 3;  // Assuming this is the state for Closed Case
        current.work_notes = 'Incident created and Case is auto-closed';
        current.update();
    }
}

function copyAttachment(inc, recordID) {
    GlideSysAttachment.copy(current.sys_class_name, current.sys_id, inc.sys_class_name, inc.sys_id);
}

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

SanjivMeher
Mega Patron
Mega Patron

I would make few improvements to the script. I would also add the case id as parent in the incident. And then close the case

 

function confirmCreateIncident() {

    var conf = confirm("Are you sure you want to CREATE INCIDENT?\n\n");
    if (conf == true) {
        gsftSubmit(null, g_form.getFormElement(), 'create_incident');
    } else
        return false;
}

if (typeof window == 'undefined')
    doCreateINC();

function doCreateINC() {
    var inc = new GlideRecord('incident');
    inc.initialize();
    var worknotes = current.work_notes.getJournalEntry(-1);
    var addcomments = current.comments.getJournalEntry(-1);

    // inc.number = getNextObjNumberPadded();
    // inc.assignment_group = current.assignment_group.getValue('sys_id');
    inc.assigned_to = current.assigned_to.getValue('sys_id');
    inc.short_description = [current.number] + ' - ' + current.short_description;
    inc.description = '[Transformed from ' + [current.number] + '] ' + "\n" + current.description;
    inc.work_notes = worknotes;
    inc.comments = addcomments;
    inc.parent = current.getValue('sys_id');;
    inc.caller_id = current.opened_by.getValue('sys_id');
    inc.contact_type = 'self-service';


    var incSuccess = inc.insert();
    if (incSuccess) {
        copyAttachment(inc, current.sys_id);
        action.setRedirectURL(inc);
        current.state = 3;  // Assuming this is the state for Closed Case
        current.work_notes = 'Incident created and Case is auto-closed';
        current.update();
    }
}

function copyAttachment(inc, recordID) {
    GlideSysAttachment.copy(current.sys_class_name, current.sys_id, inc.sys_class_name, inc.sys_id);
}

Please mark this response as correct or helpful if it assisted you with your question.

       current.update();

That's what I forgot about 🙂 

Thanks for answer!