- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
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
4 weeks ago
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
4 weeks ago
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);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
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.