- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 02:07 AM
Hi Guys,
I'm using below script to get the variables are associated with RITM and Task. The code is providing the result of more than one catalog variables but not providing the associated catalog task numbers. Can you help how to get the mentioned below output? I'm seeing the error is part of taskInfo['Variables'] = varList; and return taskInfo;. Can you help to resolve?
var taskInfo = {};
var varList = [];
var grTask = new GlideRecord('sc_task');
grTask.addQuery('state', '8');
// grTask.addQuery('assignment_group', '2d4ac16d1bb159106ece2fc5604bcb26');
grTask.query();
while (grTask.next()) {
taskInfo = {
'Task_Number': grTask.number.toString(),
'Service_Request': grTask.request.number.toString(),
'RITM_Number': grTask.request_item.getDisplayValue(),
'Short_Description': grTask.short_description.toString(),
'Description':grTask.description.toString(),
'State':grTask.state.getDisplayValue().toString(),
//'item': grTask.cat_item.name.toString(),
'Business_Justification':grTask.request.special_instructions.toString(),
'Requested_For': grTask.request_item.request.requested_for.getDisplayValue()
};
var grVar = new GlideRecord('sc_item_option_mtom');
grVar.addQuery('request_item', grTask.request_item);
grVar.query();
// while (grVar.hasNext()) {
while (grVar.next()) {
var fieldName = grVar.sc_item_option.item_option_new.name.toString();
//var type = grVar.sc_item_option.item_option_new.type.toString();
var value = grVar.sc_item_option.value.toString();
varList.push({
'Variable_Name': fieldName,
// 'type': type,
'Variable_Value': value
});
taskInfo['Variables'] = varList;
}
//return taskInfo;
//}
//return taskInfo;
}
return taskInfo;
})(request, response);
Expected Result:
"result": {
"Task_Number": "SCTASK0253304",
"Service_Request": "REQ0151698",
"RITM_Number": "RITM0179353",
"Short_Description": "Test1",
"Description": "",
"State": "Assigned",
"Business_Justification": "test",
"Requested_For": "Pankaj Binwal",
"Variables": [
{
"Variable_Name": "refUserID",
"Variable_Value": ""
},
"Task_Number": "SCTASK0253305",
"Service_Request": "REQ0151699",
"RITM_Number": "RITM0179354",
"Short_Description": "Test2",
"Description": "",
"State": "Assigned",
"Business_Justification": "test",
"Requested_For": "Pankaj Binwal",
"Variables": [
{
"Variable_Name": "refUserID",
"Variable_Value": ""
},
Regards,
Suresh.
Suresh.
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 07:18 AM
Try using this.
var taskInfo = [];
var grTask = new GlideRecord('sc_task');
grTask.addQuery('state', '8');
// grTask.addQuery('assignment_group', '2d4ac16d1bb159106ece2fc5604bcb26');
grTask.query();
while (grTask.next()) {
var temp = {};
temp.Task_Number = grTask.number.toString();
temp.Service_Request = grTask.request.number.toString();
temp.RITM_Number = grTask.request_item.getDisplayValue();
temp.Short_Description = grTask.short_description.toString();
temp.Description = grTask.description.toString();
temp.State = grTask.state.getDisplayValue().toString();
//temp.item = grTask.cat_item.name.toString();
temp.Business_Justification = grTask.request.special_instructions.toString();
temp.Requested_For = grTask.request_item.request.requested_for.getDisplayValue();
var grVar = new GlideRecord('sc_item_option_mtom');
grVar.addQuery('request_item', grTask.request_item);
grVar.query();
var varArray = [];
// if (grVar.hasNext()) {
while (grVar.next()) {
var fieldName = grVar.sc_item_option.item_option_new.name.toString();
//var type = grVar.sc_item_option.item_option_new.type.toString();
var value = grVar.sc_item_option.value.toString();
var tempVariable = {}
tempVariable.Variable_Name = fieldName;
tempVariable.Variable_Value = value;
varArray.push(tempVariable);
}
temp.Variables = varArray;
taskInfo.push(temp);
//return taskInfo;
//}
//return taskInfo;
}
return taskInfo;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 02:25 AM
Hello Suresh,
Please check once with below script:
You need to put taskInfo['Variables'] = varList; outside while () loop
var taskInfo = {};
var varList = [];
var grTask = new GlideRecord('sc_task');
grTask.addQuery('state', '8');
// grTask.addQuery('assignment_group', '2d4ac16d1bb159106ece2fc5604bcb26');
grTask.query();
while (grTask.next()) {
taskInfo = {
'Task_Number': grTask.number.toString(),
'Service_Request': grTask.request.number.toString(),
'RITM_Number': grTask.request_item.getDisplayValue(),
'Short_Description': grTask.short_description.toString(),
'Description':grTask.description.toString(),
'State':grTask.state.getDisplayValue().toString(),
//'item': grTask.cat_item.name.toString(),
'Business_Justification':grTask.request.special_instructions.toString(),
'Requested_For': grTask.request_item.request.requested_for.getDisplayValue()
};
var grVar = new GlideRecord('sc_item_option_mtom');
grVar.addQuery('request_item', grTask.request_item);
grVar.query();
// while (grVar.hasNext()) {
while (grVar.next()) {
var fieldName = grVar.sc_item_option.item_option_new.name.toString();
//var type = grVar.sc_item_option.item_option_new.type.toString();
var value = grVar.sc_item_option.value.toString();
varList.push({
'Variable_Name': fieldName,
// 'type': type,
'Variable_Value': value
});
}
taskInfo['Variables'] = varList;
//return taskInfo;
//}
//return taskInfo;
}
return taskInfo;
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 02:29 AM
Hi Mahendra,
Thanks for the update. The output not provides the task number details. It shows only one task number and providing the more than one task number variables. Can you refer the expected output in the above screen. I'm looking the same as output.
Regards,
Suresh.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 02:35 AM
Okay.. so if you want all task in single response then please check below:
created a new Variable var taskRecordList = []
and insert each task record data in this array list
taskRecordList.push(taskInfo)
var taskInfo = {};
var varList = [];
var taskRecordList = [];
var grTask = new GlideRecord('sc_task');
grTask.addQuery('state', '8');
// grTask.addQuery('assignment_group', '2d4ac16d1bb159106ece2fc5604bcb26');
grTask.query();
while (grTask.next()) {
taskInfo = {
'Task_Number': grTask.number.toString(),
'Service_Request': grTask.request.number.toString(),
'RITM_Number': grTask.request_item.getDisplayValue(),
'Short_Description': grTask.short_description.toString(),
'Description':grTask.description.toString(),
'State':grTask.state.getDisplayValue().toString(),
//'item': grTask.cat_item.name.toString(),
'Business_Justification':grTask.request.special_instructions.toString(),
'Requested_For': grTask.request_item.request.requested_for.getDisplayValue()
};
var grVar = new GlideRecord('sc_item_option_mtom');
grVar.addQuery('request_item', grTask.request_item);
grVar.query();
// while (grVar.hasNext()) {
while (grVar.next()) {
var fieldName = grVar.sc_item_option.item_option_new.name.toString();
//var type = grVar.sc_item_option.item_option_new.type.toString();
var value = grVar.sc_item_option.value.toString();
varList.push({
'Variable_Name': fieldName,
// 'type': type,
'Variable_Value': value
});
}
taskInfo['Variables'] = varList;
//return taskInfo;
//}
//return taskInfo;
taskRecordList.push(taskInfo);
}
return taskRecordList;
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 06:28 AM
Hello
Did you got a chance to check with above code? does it worked for you? If yes, then please do close this thread/question by marking the appropriate response as correct.
If you still need any further help or guidance on this then please update those on this question.
Thanks