- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2025 10:36 PM
I used a Flow and wanted to put the question text of the item into column A of a table, and the item's value into column B. I added an Action (JavaScript), but I couldn't retrieve the content.
(function execute(inputs, outputs) {
var reqItemId = inputs.req_item_id;
var result = {};
var m2m = new GlideRecord('sc_item_option_mtom');
m2m.addQuery('request_item', reqItemId);
m2m.query();
while (m2m.next()) {
var option = m2m.sc_item_option.getRefRecord();
var variable = option.item_option_new.getRefRecord();
var varName = variable.name.toString();
result[varName] = {
question: variable.question.toString(),
value: option.value.toString()
};
}
outputs.results = result;
})(inputs, outputs);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2025 12:03 AM
Hi @艶博李
I've shared a script to retrieve all results from a catalog after submitting an entry.
https://www.servicenow.com/community/developer-forum/querying-ritm-based-on-catalog-item-variables/m...
This might help with what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2025 10:46 PM
Hi @艶博李
Right now, your script is building an object (result) with question and value — but Flow Designer outputs can’t directly “map” nested JSON into columns. You’ll need to explicitly insert/update a record in your target table.
below is your Corrected script:
(function execute(inputs, outputs) {
var reqItemId = inputs.req_item_id;
// Target table (replace with your table)
var targetTable = 'u_target_table';
var m2m = new GlideRecord('sc_item_option_mtom');
m2m.addQuery('request_item', reqItemId);
m2m.query();
while (m2m.next()) {
// Get option and variable
var option = m2m.sc_item_option.getRefRecord();
var variable = option.item_option_new.getRefRecord();
// Extract question & value
var questionText = variable.question.toString();
var valueText = option.value.toString();
// Insert into your target table
var gr = new GlideRecord(targetTable);
gr.initialize();
gr.u_question = questionText; // Column A
gr.u_value = valueText; // Column B
gr.u_request_item = reqItemId; // optional for traceability
gr.insert();
}
outputs.success = true;
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2025 12:03 AM
Hi @艶博李
I've shared a script to retrieve all results from a catalog after submitting an entry.
https://www.servicenow.com/community/developer-forum/querying-ritm-based-on-catalog-item-variables/m...
This might help with what you need.