How to get the Catalog task form fields, variables, MVRS variables by using scripted REST API call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2022 10:05 AM
Hi Team,
Can someone please help me.
I am using Scripted REST API, GET method.
Requirement: On the catalog task table(sc_task), passing the Catalog sys_id, Assignment group, if it matches from sc_task table. I need to get All the tasks information
1. sc_task form fields
2. sc_task variables
3. sc_task MVRS variables.
But in the response, I am unable to get the proper data. Please help me.
Relative path: /{cat_id}/{assignment_group}
Scripted REST API:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var cat_id = request.pathParams.cat_id;
var assignment_group = request.pathParams.assignment_group;
var taskInfo = {};
var taskDetails = {};
var ritmFields = {};
try {
var grTask = new GlideRecord('sc_task');
grTask.addQuery("cat_item",cat_id);
grTask.addQuery("assignment_group.name",assignment_group);
grTask.query();
var taskList = [];
var sc_taskList = [];
while (grTask.next()) {
var task_number ={};
task_number.number = grTask.number.toString();
// get field values
var fields = grTask.getFields();
for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
taskInfo[glideElement.getName().toString()] = glideElement.toString();
}
}
//Get the object containing the catalog variables.
sctaskVariables = grTask.variables;
var mrvs = JSON.parse(grTask.variables.giam_multi_row_set);
var iVar= {};
var objc = {};
//sc_taskList.push(grTask.number);
iVar.sc_tasknumber = grTask.number.toString();
for (var j = 0; j < mrvs.length; j++) {
iVar = mrvs[j];
taskList.push(iVar);
}
}
taskInfo["MVRS"] = taskList;
return taskInfo;
} catch (e) {
response.setError(new sn_ws_err.NotFoundError('specified ritm was not found.')); // error - record not found
}
})(request, response);
Response: I am unable to get proper response, it is clubbed together.
Only single sc_task number printed in result object and in MVRS, all catalog tasks clubbed together.
{
"result": {
"number": "SCTASK14779824",
"u_stp_active": "false",
"state": "1",
"sys_created_by": "system",
"request": "b6f85fe61b91dd14711a6397b04bcb1e",
"assignment_group": "f91bbc3cdb4a5490f2821bbf299619c4",
"urgency": "3",
"MVRS": [
{
"test_application": "1612e701db86d090220749a239961246",
"status": "Open"
},
{
"test_application": "1612e701db86d090220749a239961247",
"status": "Open"
},
]
}
}
Expected Response:
If multiple tasks exists
[{
task: sc_task1
form fields: {}
variables:[{}]
MVRS: [{}]
},
{
task: sc_task2
form fields: {"number", "CATASK001", Assignment Group: "TEST", item: "TEST ITEM"}
variables:[{}]
MVRS: [{}]
}]
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2022 02:49 PM
If you want something pre-built, you can use SN Pro Tips — Get RITM Variables via SRAPI.
Looking at your script, you've crossed over using taskDetails and task_number meaning you'll not be creating the objects you want.
You can also leverage GlobalServiceCatalogUtil to get variable information.