Include the INC attachment to the converted SCTASK

Community Alums
Not applicable

I have a custom UI action to convert an INC to an SCTASK, I need to also include any attachments that were included on the INC. What am I missing in my script? Please help! See my script below.

 

 

// Below few lines of code works as a Client side script
function CreateStask() {
   
    if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('comments', true); // Setting Additional comments are manditory.
g_form.showFieldMsg('comments','Additional comments are mandatory when converting an Incident to SC Task.','error');


       
return false; //Abort submission
}
gsftSubmit(null, g_form.getFormElement(), 'create_catalog'); //MUST call the 'Action name'(Here action name is 'create_catalog' set in this UI Action
}


createTask();

function createTask(){
var Req = new GlideRecord('sc_request');
Req.initialize();
Req.setValue('short_description',current.short_description);
Req.requested_for= current.caller_id;
Req.insert();

var RITM = new GlideRecord('sc_req_item');
RITM.initialize();
RITM.setValue('request', Req.sys_id);
RITM.setValue('parent', Req.sys_id);
RITM.setValue('assignment_group',current.assignment_group);
RITM.setValue('short_description',current.short_description); // give short description for the task
RITM.insert();
//gs.addInfoMessage(RITM.number);   //This line just for dispalying RITM number after conversion from incident to sc task.

var taskRec = new GlideRecord('sc_task');  
taskRec.initialize();
taskRec.setValue('request_item',RITM.sys_id);
//taskRec.setValue('request.requested_for',current.caller_id);
taskRec.setValue('assignment_group',current.assignment_group);
taskRec.setValue('assigned_to',current.assigned_to);
taskRec.setValue('short_description',current.short_description); // give short description for the task
taskRec.setValue('description',current.description);



var setworknotes='SCTASK created from incident '+current.number;
taskRec.parent=current.number;
taskRec.work_notes.setJournalEntry(setworknotes);
taskRec.insert();
//gs.addInfoMessage(taskRec.number);


var setwrknotesinci='Your incident has been converted to a Service Catalog Task.  All incident information has been transitioned over to  '+taskRec.number;

current.work_notes.setJournalEntry(setwrknotesinci);

current.state ='8'; // Cancelling the incident after conversion to SC Task
current.setValue('active', 'false'); // Incident will be active = false after conversion

current.update();
action.setRedirectURL(taskRec);
}
3 ACCEPTED SOLUTIONS

Swapna Abburi
Mega Sage
Mega Sage

Hi @Community Alums 

You can use GlideSysAttachment.copy() method to copy attachments from incident to SC task.

add below lines of code to your script.

var tasksysID = taskRec.insert();

GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);

View solution in original post

Community Alums
Not applicable

That worked! Thank you very much!

View solution in original post

Pasting the complete code here:

 

function CreateStask() {
   
    if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('comments'true); // Setting Additional comments are manditory.
g_form.showFieldMsg('comments','Additional comments are mandatory when converting an Incident to SC Task.','error');



       
return false//Abort submission
}
gsftSubmit(null, g_form.getFormElement(), 'create_catalog'); //MUST call the 'Action name'(Here action name is 'create_catalog' set in this UI Action
}



createTask();

 

function createTask(){
var Req = new GlideRecord('sc_request');
Req.initialize();
Req.setValue('short_description',current.short_description);
Req.requested_for= current.caller_id;
Req.insert();

 

var RITM = new GlideRecord('sc_req_item');
RITM.initialize();
RITM.setValue('request'Req.sys_id);
RITM.setValue('parent'Req.sys_id);
RITM.setValue('assignment_group',current.assignment_group);
RITM.setValue('short_description',current.short_description); // give short description for the task
RITM.insert();
//gs.addInfoMessage(RITM.number);   //This line just for dispalying RITM number after conversion from incident to sc task.



var tasksysID = taskRec.insert();
GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);



var taskRec = new GlideRecord('sc_task');  
taskRec.initialize();
taskRec.setValue('request_item',RITM.sys_id);
//taskRec.setValue('request.requested_for',current.caller_id);
taskRec.setValue('assignment_group',current.assignment_group);
taskRec.setValue('assigned_to',current.assigned_to);
taskRec.setValue('short_description',current.short_description); // give short description for the task
taskRec.setValue('description',current.description);



var setworknotes='SCTASK created from incident '+current.number;
taskRec.parent=current.number;
taskRec.work_notes.setJournalEntry(setworknotes);

var tasksysID = taskRec.insert();

GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);
//gs.addInfoMessage(taskRec.number);



var setwrknotesinci='Your incident has been converted to a Service Catalog Task.  All incident information has been transitioned over to  '+taskRec.number;
current.work_notes.setJournalEntry(setwrknotesinci);

 

current.state ='8'// Cancelling the incident after conversion to SC Task
current.setValue('active''false'); // Incident will be active = false after conversion

 

current.update();
action.setRedirectURL(taskRec);
}

View solution in original post

4 REPLIES 4

Swapna Abburi
Mega Sage
Mega Sage

Hi @Community Alums 

You can use GlideSysAttachment.copy() method to copy attachments from incident to SC task.

add below lines of code to your script.

var tasksysID = taskRec.insert();

GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);

Community Alums
Not applicable

That worked! Thank you very much!

Community Alums
Not applicable

Hello Swapna,

 

Please tell me where your added lines of script should go in my script that will allow the other lines to operate.

When I added your lines below the current.work_notes.setJournalEntry(setwrknotesinci); line, it included the INC attachment but did not include the notes that go in the SCTASK. Please instruct on how the below script should be lined.

 

// Below few lines of code works as a Client side script
function CreateStask() {
   
    if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('comments', true); // Setting Additional comments are manditory.
g_form.showFieldMsg('comments','Additional comments are mandatory when converting an Incident to SC Task.','error');


       
return false; //Abort submission
}
gsftSubmit(null, g_form.getFormElement(), 'create_catalog'); //MUST call the 'Action name'(Here action name is 'create_catalog' set in this UI Action
}


createTask();

function createTask(){
var Req = new GlideRecord('sc_request');
Req.initialize();
Req.setValue('short_description',current.short_description);
Req.requested_for= current.caller_id;
Req.insert();

var RITM = new GlideRecord('sc_req_item');
RITM.initialize();
RITM.setValue('request', Req.sys_id);
RITM.setValue('parent', Req.sys_id);
RITM.setValue('assignment_group',current.assignment_group);
RITM.setValue('short_description',current.short_description); // give short description for the task
RITM.insert();
//gs.addInfoMessage(RITM.number);   //This line just for dispalying RITM number after conversion from incident to sc task.


var tasksysID = taskRec.insert();
GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);


var taskRec = new GlideRecord('sc_task');  
taskRec.initialize();
taskRec.setValue('request_item',RITM.sys_id);
//taskRec.setValue('request.requested_for',current.caller_id);
taskRec.setValue('assignment_group',current.assignment_group);
taskRec.setValue('assigned_to',current.assigned_to);
taskRec.setValue('short_description',current.short_description); // give short description for the task
taskRec.setValue('description',current.description);


var setworknotes='SCTASK created from incident '+current.number;
taskRec.parent=current.number;
taskRec.work_notes.setJournalEntry(setworknotes);
taskRec.insert();
//gs.addInfoMessage(taskRec.number);


var setwrknotesinci='Your incident has been converted to a Service Catalog Task.  All incident information has been transitioned over to  '+taskRec.number;
current.work_notes.setJournalEntry(setwrknotesinci);

current.state ='8'; // Cancelling the incident after conversion to SC Task
current.setValue('active', 'false'); // Incident will be active = false after conversion

current.update();
action.setRedirectURL(taskRec);
}

Pasting the complete code here:

 

function CreateStask() {
   
    if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('comments'true); // Setting Additional comments are manditory.
g_form.showFieldMsg('comments','Additional comments are mandatory when converting an Incident to SC Task.','error');



       
return false//Abort submission
}
gsftSubmit(null, g_form.getFormElement(), 'create_catalog'); //MUST call the 'Action name'(Here action name is 'create_catalog' set in this UI Action
}



createTask();

 

function createTask(){
var Req = new GlideRecord('sc_request');
Req.initialize();
Req.setValue('short_description',current.short_description);
Req.requested_for= current.caller_id;
Req.insert();

 

var RITM = new GlideRecord('sc_req_item');
RITM.initialize();
RITM.setValue('request'Req.sys_id);
RITM.setValue('parent'Req.sys_id);
RITM.setValue('assignment_group',current.assignment_group);
RITM.setValue('short_description',current.short_description); // give short description for the task
RITM.insert();
//gs.addInfoMessage(RITM.number);   //This line just for dispalying RITM number after conversion from incident to sc task.



var tasksysID = taskRec.insert();
GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);



var taskRec = new GlideRecord('sc_task');  
taskRec.initialize();
taskRec.setValue('request_item',RITM.sys_id);
//taskRec.setValue('request.requested_for',current.caller_id);
taskRec.setValue('assignment_group',current.assignment_group);
taskRec.setValue('assigned_to',current.assigned_to);
taskRec.setValue('short_description',current.short_description); // give short description for the task
taskRec.setValue('description',current.description);



var setworknotes='SCTASK created from incident '+current.number;
taskRec.parent=current.number;
taskRec.work_notes.setJournalEntry(setworknotes);

var tasksysID = taskRec.insert();

GlideSysAttachment.copy("incident", current.sys_id, "sc_task", tasksysID);
//gs.addInfoMessage(taskRec.number);



var setwrknotesinci='Your incident has been converted to a Service Catalog Task.  All incident information has been transitioned over to  '+taskRec.number;
current.work_notes.setJournalEntry(setwrknotesinci);

 

current.state ='8'// Cancelling the incident after conversion to SC Task
current.setValue('active''false'); // Incident will be active = false after conversion

 

current.update();
action.setRedirectURL(taskRec);
}