- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 01:32 AM
Hi All,
I am trying to fetch the variables and it's values populated while creating record producer in a server script.
Using GlideRecord on the Record producer base table is not working. So, I am using GlideRecord on 'sc_multi_row_question_answer' to get the values. Currently I am getting below response
{
"preImplementationPlan ": [
{
"duration2": "3 hrs"
},
{
"implementation_plan2": "testing plan"
},
{
"teams2": "NOC"
},
{
"teams2": "db team"
},
{
"duration2": "2 hrs"
},
{
"implementation_plan2": "testing db team"
}
]
}
But expected response is as below
{
"preImplementationPlan ": [
{
"implementation_plan2": "testing plan",
"teams2": "NOC"
"duration2": "3 hrs"
},
{
"implementation_plan2": "testing db team",
"teams2": "db team",
"duration2": "2 hrs"
}
]
}
Below is the code that i am using
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 12:34 AM
Hi @Kieran Anson ,
Thank you for explaining with example. But I'm trying to get the variables from the record producer.
I found the solution. I'm posting it below.
var Arr = [];
var test = {};
var mrvs = new GlideRecord('sc_multi_row_question_answer');
mrvs.addQuery('parent_id', '5ef3c42593ba4210d783bba97bba10b0');
mrvs.addQuery('variable_set', 'ab4ea5b4937a4210d783bba97bba10a7');
mrvs.orderBy('row_index'); // Ensure that results are ordered by row_index
mrvs.query();
var currentRowIndex = null;
var preImplementationPlan = {};
while (mrvs.next()) {
var rowIndex = mrvs.getValue('row_index');
if (currentRowIndex !== rowIndex) {
if (currentRowIndex !== null) {
Arr.push(preImplementationPlan);
}
preImplementationPlan = {};
currentRowIndex = rowIndex;
}
preImplementationPlan[mrvs.item_option_new.name.toString()] = mrvs.getValue('value');
}
// Add the last set of variables
if (Object.keys(preImplementationPlan).length > 0) {
Arr.push(preImplementationPlan);
}
test["preImplementationPlan"] = Arr;
gs.addInfoMessage(JSON.stringify(test));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 08:03 AM
Personally wouldn't use this approach, as it's not conforming with how access is intended
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 05:40 PM
Hi @Vidya Shree ,
Sharing a sample code that I have created, where I drilled down the object from a parent to a child key-value pair until I got the value. Using multiple JavaScript techniques with a combination of ServiceNow objects.
Btw, this is not production code, I created it for a demo purpose to fetch and display the values from the server to the client side.
You can watch the details from 36:28 to 48:40
Here is Where: Scripting in ServiceNow Fundamentals
Please mark as helpful and accept as solution if you find it lucrative.