Converting an incident to a ritm?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 12:37 PM
Hello all,
currently we have a form action called "create request" on the incident form to create a request from an incident. There is now a requirement to copy key information from the incident to the requested item such as attachments, work notes, additional comments, description, short description, assignment group, assigned to, and caller (which would be requested for). The current UI Action we have is the OOB "create request" UI Action. Here is the script for reference:
//Update saves incidents before going to the catalog homepage
current.update();
var url;
var activeCatalogsCount = sn_sc.Catalog.getCatalogCount();
if (activeCatalogsCount === 1) {
// url = "catalog_home.do?sysparm_view=catalog_default&sysparm_parent_table=" + current.sys_class_name + "&sysparm_parent_sys_id=" + current.sys_id;
url = 'catalog_home.do?sysparm_view=catalog_default&sysparm_parent_sys_id=' +current.sys_id+'&sysparm_parent_table=' + current.sys_class_name;
}
else {
//url = "catalogs_home.do?sysparm_view=catalogs_default&sysparm_parent_table=" + current.sys_class_name + "&sysparm_parent_sys_id=" + current.sys_id;
url = 'catalog_home.do?sysparm_view=catalog_default&sysparm_parent_sys_id=' +current.sys_id+'&sysparm_parent_table=' + current.sys_class_name;
}
action.setRedirectURL(url);
There is an after insert business rule running on the incident table created to close the incident:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',current.parent);
inc.query();
if(inc.next())
{
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
if(gr.next());
inc.work_notes = 'Incident has been converted to a '+gr.getDisplayValue('cat_item')+' under '+gr.getValue('number')+'.';
inc.state = '8';
//inc.parent = current.number;
inc.update();
gs.eventQueue("SKX_Incident_Converted_INC_To_REQ", current, gs.getUserID(), gs.getUserName()); // This will trigger notification.
}
})(current, previous);
I have tried creating this client script to solve the requirement, however, it is not working:
function onLoad() {
//Type appropriate comment here, and begin script below
var gURL = new GlideURL();
gURL.setFromCurrent();
var incidentID = gURL.getParam("sysparm_incident_id");
if(incidentID){
/* Verified this request is a conversion from an incident. Use the sys_id to create a new GlideRecord object with the incident data */
var grINT = new GlideRecord('incident');
grINT.get(incidentID);
//Mapping each of the Incident fields to the relevant Request fields
g_form.setValue('requested_for', grINT.caller_id);
g_form.setValue('assignment_group', grINT.assignment_group);
g_form.setValue('assigned_to', grINT.assigned_to);
g_form.setValue('short_description', grINT.short_description);
g_form.setValue('description', grINT.description);
}
}
This script I have found in this article: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694006
I have been working to understand scripting/javascript, however, I have not quite gotten it yet. Does anyone have a script to share that will work for my requirements?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 03:16 AM
The script you mentioned is not provided, but I can guide you on how to modify the existing UI Action to copy the required fields from the Incident to the Requested Item. Here are the steps:
1. Navigate to System UI > UI Actions.
2. Search for the "Create Request" UI Action.
3. Open the UI Action and scroll down to the Script section.
4. Modify the script to copy the required fields from the Incident to the Requested Item. Here is a sample script:
javascript
var req = new GlideRecord('sc_request');
req.initialize();
req.short_description = current.short_description;
req.description = current.description;
req.assignment_group = current.assignment_group;
req.assigned_to = current.assigned_to;
req.caller_id = current.caller_id;
req.insert();
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = req.sys_id;
ritm.short_description = current.short_description;
ritm.description = current.description;
ritm.assignment_group = current.assignment_group;
ritm.assigned_to = current.assigned_to;
ritm.insert();
// Copy attachments
GlideSysAttachment.copy('incident', current.sys_id, 'sc_req_item', ritm.sys_id);
// Copy work notes
var wn = new GlideRecord('sys_journal_field');
wn.addQuery('element_id', current.sys_id);
wn.query();
while (wn.next()) {
var newWn = new GlideRecord('sys_journal_field');
newWn.initialize();
newWn.element_id = ritm.sys_id;
newWn.value = wn.value;
newWn.insert();
}
// Copy additional comments
var ac = new GlideRecord('sys_journal_field');
ac.addQuery('element_id', current.sys_id);
ac.query();
while (ac.next()) {
var newAc = new GlideRecord('sys_journal_field');
newAc.initialize();
newAc.element_id = ritm.sys_id;
newAc.value = ac.value;
newAc.insert();
}
5. Update the UI Action.
Please note that this is a basic script and may need to be adjusted based on your specific requirements and ServiceNow setup. Always test scripts in a sub-production environment before deploying to production.
nowKB.com
If you want to know any information about Service Now . Visit to https://nowkb.com/home

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 06:54 AM
I have done a project on this. Please go through the below link and it has the complete downloadable package for converting an incident to a request with step by step configuration.
Convert Incident to RITM - Guide
Thanks,
Narsing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 11:30 AM
Hi @astanley ,
Please refer to below KB article.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694006
Regards,
Sandeep RAj