- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 06:52 AM
We have a UI Action 'Create Story' on sc tasks. When user clicks on it, a new story will be created and sc task will be closed. The new requirement is to capture the variables from sc task (part of variable editor - comes from catalog item) and copy them to story. Please assist.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 07:58 PM
in client side also it will be difficult to determine.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 08:42 PM
so what script did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 06:01 AM - edited 03-17-2023 06:02 AM
@Ankur Bawiskar I had the similar requirement for RITM too (when user clicks on create story UI action on ritm form), used the below script. But I don't see any table in servicenow that stores sc task variables and its values.
var story = new GlideRecord("rm_story");
story.initialize();
story.short_description = current.short_description;
story.insert();
var storySysid = story.sys_id;
var ritmVar = new GlideRecord('sc_item_option_mtom');
ritmVar.addQuery('request_item', current.getUniqueValue());
ritmVar.addNotNullQuery('sc_item_option.value');
ritmVar.orderBy('sc_item_option.order');
ritmVar.query();
var fields = '';
while (ritmVar.next()) {
fields = fields + ritmVar.sc_item_option.item_option_new.question_text + ": " + current.variable_pool[ritmVar.sc_item_option.item_option_new.name].getDisplayValue() + "\n";
}
story.u_ritm_variables = fields;
story.update();
action.setRedirectURL(story);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 06:55 AM
update as this
var story = new GlideRecord("rm_story");
story.initialize();
story.short_description = current.short_description;
story.insert();
var storySysid = story.sys_id;
var ritmVar = new GlideRecord('sc_item_option_mtom');
ritmVar.addQuery('request_item', current.request_item); // use RITM field on sc_task to query
ritmVar.addNotNullQuery('sc_item_option.value');
ritmVar.orderBy('sc_item_option.order');
ritmVar.query();
var fields = '';
while (ritmVar.next()) {
fields = fields + ritmVar.sc_item_option.item_option_new.question_text + ": " + current.variable_pool[ritmVar.sc_item_option.item_option_new.name].getDisplayValue() + "\n";
}
story.u_ritm_variables = fields;
story.update();
action.setRedirectURL(story);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 07:26 AM
The above script is querying the ritm from sc task and fetch ritm variables, but I need the variables present on sc task form. We have many catalog items where some variables are visible only on sc tasks, but not on ritm.