- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 12:49 PM
Greetings,
I am trying to create a UI Action that will allow the Service Desk to add Additional SCTASK(s) to any Open RITM.
Thank you in advance for any guidance 🙂
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 01:17 PM - edited 04-14-2023 01:21 PM
Copy the below script to your UI action:
UI Action name - " whatever "
Table - sc_req_item
Client - keep it un-ticked (false)
var sc = new GlideRecord('sc_task');
sc.newRecord();
sc.setValue('short_description', current.getValue('short_description'));
sc.setValue('description', current.getValue('description'));
sc.setValue('assignment_group', current.getValue('assignment_group'));
sc.setValue('request_item', current.getValue('sys_id'));
sc.setValue('request', current.getValue('request'));
// add required fields
var recSysId = sc.insert(); // create catalog task
// to copy variable on catalog task
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item.numberSTARTSWITH' + current.getValue('number'));
gr.query();
while (gr.next()) {
var grt = new GlideRecord('sc_item_variables_task');
grt.newRecord();
grt.setValue('task', recSysId);
grt.setValue('variable', gr.sc_item_option.item_option_new.toString());
grt.insert();
}
Please be kind enough to mark my answer correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 01:17 PM
@Leon Els Sure, here's a sample UI Action script for adding additional SCTASK(s) to an open RITM in ServiceNow:
(function() { var ritmSysId = g_form.getUniqueValue(); // Get the unique ID of the RITM record var gr = new GlideRecord('sc_task'); // Create a new GlideRecord object for the SCTASK table gr.initialize(); // Initialize the GlideRecord object gr.request_item.setDisplayValue(ritmSysId); // Set the Request Item field to the RITM sys_id gr.short_description = "New SCTASK"; // Set a default short description gr.insert(); // Insert the new SCTASK record // Refresh the RITM form to show the new SCTASK var ritmForm = g_form.getFormElement(); ritmForm.action = ritmForm.action + "&sysparm_clear_stack=true"; ritmForm.submit(); })();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 01:20 PM
Hi,
To create a UI action in ServiceNow that allows the Service Desk to add additional SCTASK(s) to any Open RITM, you can follow these steps:
Navigate to the RITM (Requested Item) form and click on the "UI Actions" related list.
Click the "New" button to create a new UI action.
Fill out the form to create the UI action. Here are some suggested values for the fields:
- Name: Add Additional SCTASK(s)
- Table: Requested Item [sc_req_item]
- Action name: add_sctask
- Client: true
- Onclick: openAdditionalSCTask()
Save the UI action.
Create a script include to contain the code that will be executed when the UI action is clicked. Here is some example code:
function openAdditionalSCTask() {
var ga = new GlideAjax('AddSCTaskAjax');
ga.addParam('sysparm_name', 'getForm');
ga.addParam('sysparm_ritm', g_form.getUniqueValue());
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "true") {
var url = '/nav_to.do?uri=' + encodeURIComponent('task.do?sysparm_query=request_item=' + g_form.getUniqueValue());
window.open(url);
}
});
}
Create a script include with the name "AddSCTaskAjax" to contain the server-side code. Here is some example code:
var AddSCTaskAjax = Class.create();
AddSCTaskAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getForm: function() {
var ritmID = this.getParameter('sysparm_ritm');
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(ritmID)) {
var taskGR = new GlideRecord('sc_task');
taskGR.initialize();
taskGR.request_item = ritmGR.sys_id;
taskGR.insert();
return true;
} else {
return false;
}
},
type: 'AddSCTaskAjax'
});
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 01:36 PM
Thank you SO much for your guidance! I am so fortunate to have 3 responses and will advise soon 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 01:58 PM
@Rahul Kumar17 - Big thank you again! I have a quick question, please.
Is the below part of the same UI Action?
Currently, I am not sure where to paste that code (Below screenshots show what I have so far.)
Create a script include with the name "AddSCTaskAjax" to contain the server-side code. Here is some example code:
var AddSCTaskAjax = Class.create();
AddSCTaskAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getForm: function() {
var ritmID = this.getParameter('sysparm_ritm');
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(ritmID)) {
var taskGR = new GlideRecord('sc_task');
taskGR.initialize();
taskGR.request_item = ritmGR.sys_id;
taskGR.insert();
return true;
} else {
return false;
}
},
type: 'AddSCTaskAjax'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 02:09 PM
I have provided the steps.
Please go one by one
Thanks,
Rahul Kumar