Copy variables (from variable editor) from RITM/TASK to Story using UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2023 08:17 AM
Hi,
We have a UI Action 'Create Story' on RITM and Tasks. When user clicks on it, a new story will be created and RITM/Task will be closed. The new requirement is to capture the variables from RITM/Task (part of variable editor - comes from catalog item) and copy them to new tab on the story for variables. How to achieve this requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2023 11:31 AM
You can use the GlideRecordToObject function to copy all of the variable names and values to a multi-line text field on the story. I assume your UI Action script is not running at the Client level (box unchecked). You can add a GlideRecord like this, or append if you already have a GR to retrieve the RITM record:
var variablesGR = new GlideRecord('sc_req_item');
variablesGR.get('sys_id', current.sys_id);
var desc = JSON.stringify(new GlideRecordToObject().toObject(variablesGR.variable_pool));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2023 12:55 PM
Hi Brad,
Thank you. Is it possible to introduce variable editor on story and copy all the variables over there instead of saving them in multi line text box?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2023 03:51 PM
From what I've seen on adding a Variable Editor section on a Form Layout of a record, this will show when the record was created via a Record Producer that has the variables defined. The other records created without the Record Producer don't show the Variables section. So this would be tricky in a UI Action that is active for various Catalog Items with different variable names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2023 12:40 PM - edited ‎02-28-2023 12:41 PM
GlideRecordToObject didn't work. So, I did a glide query on sc_item_option_mtom table and fetched the RITM variables and its values.
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";
}
Have similar requirement on sc task table too. But couldn't find any table on sc task that stores both variable label and value. Can you please assist?