- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 05:06 AM - edited 01-08-2024 07:03 AM
Hi,
i have a problem cause I prepared a button form the 'burger' List on Case form as You can See Below:
(DK INC)
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);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 10:01 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 10:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 02:30 PM
current.update();
That's what I forgot about 🙂
Thanks for answer!