- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2023 06:38 AM
I have created a UI action that converts an Incident to a Request (SCTASK). I found a script that works really well, it cancels the Incident and creates the request with all of the relevant information. My question is, is there a way to modify the script that will copy the task number into the notes of the incident after the task has been created? Below is the script I am using to do the conversion.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2023 06:57 AM
Hi @RobertPC,
You're not far off:
// 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 mandatory.
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);
taskRec.insert();
//gs.addInfoMessage(taskRec.number);
current.comments .setJournalEntry("The Incident was canceled due to wrong ticket type, CDSID created a Service Catalog Task out of it " + taskRec.getDisplayValue());
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);
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2023 06:57 AM
Hi @RobertPC,
You're not far off:
// 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 mandatory.
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);
taskRec.insert();
//gs.addInfoMessage(taskRec.number);
current.comments .setJournalEntry("The Incident was canceled due to wrong ticket type, CDSID created a Service Catalog Task out of it " + taskRec.getDisplayValue());
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);
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2023 07:04 AM
Thank you, I could not see it and it was driving me crazy.