- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 07:52 AM
Create a record in the task_ci_list table for 2 sys_id’s.
Here's what I have scripted so far.
var sysid = new GlideRecord("task_ci");
sysid.addQuery('sys_id','=','4c4148471bcdd51070fab99f034bcb40');
sysid.addQuery('sys_id','=','80361c121bd1119038f7766f034bcbb7');
sysid.query();a
sysid.insert();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 08:20 AM
You have to use below format(verify the field names);
var taskCIGR= new GlideRecord("task_ci");
taskCIGR.initialize();
taskCIGR.setValue("task","4c4148471bcdd51070fab99f034bcb40");
taskCIGR.setValue("ci","your_ci_sys_id");
taskCIGR.insert();
Similarly, for multiple sys_ids, create a for loop and insert in task_ci table
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 08:02 AM
Hey Ashle,
Can you give us more information on what you are trying to do? Any screenshots for reference?
Regards,
Muhammad
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 08:12 AM
Building out a rest api. I need to relate the two sysid's to be inserted as affected CI's listed when the change request is created from a json.
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
//expected JSON payload:
// {
// "services":"", //*required
// "short_description":"",*required
// "description": "",*required
// "assignment_group":"", //*required
// "assigned_to":"", //*required
// "assigned_to":"", //
// "Planned_Start_Date":"", //*required
// "Planned_Etart_Date", //*required
// }
// requesting info from the body
//var requestBody = request.body.data;
var body = request.body.dataString;
var parsedData = JSON.parse(body);
var fieldErr = getInvalidFields();
//Getting all the info from the change record
var desc = parsedData.description;
var shortDesc = parsedData.short_description;
var services = parsedData.business_service;
var assignGrp = parsedData.assignment_group;
var assignTo = parsedData.assigned_to;
// create a change with a gliderecord and populate all the information needed
var gr = new GlideRecord("change_request");
gr.initialize();
gr.description = desc;
gr.short_description = shortDesc;
gr.business_service = services;
gr.assignment_group = assignGrp;
gr.assigned_to = assignTo;
gr.justification = "Automated Pipeline";
gr.implementation_plan = "Automated Pipeline";
gr.backout_plan = "Rollback to previous version";
gr.test_plan = "Tested through non-prod and is now ready for production deployment";
var sysid = new GlideRecord("task_ci");
sysid.addQuery('sys_id','=','4c4148471bcdd51070fab99f034bcb40');
sysid.addQuery('sys_id','=','80361c121bd1119038f7766f034bcbb7');
sysid.query();
sysid.insert();
if (fieldErr.length > 0) {
response.setError(new sn_ws_err.BadRequestError(fieldErr.toString('500 ERROR')));
return;
}
var businessServicesID = getBusinessService(services);
gs.info("Testing endpoint Services Test " + businessServicesID);
if (!desc) {
response.setError(new sn_ws_err.BadRequestError('Description ' + parsedData.description + ' not found'));
return;
} else if (!shortDesc) {
response.setError(new sn_ws_err.BadRequestError('Short Description ' + parsedData.short_description + ' not found'));
return;
} else if (!services) {
response.setError(new sn_ws_err.BadRequestError('Services ' + parsedData.business_service + ' not found'));
return;
} else if (!assignGrp) {
response.setError(new sn_ws_err.BadRequestError('Assignment Group' + parsedData.assignment_group + ' not found'));
return;
} else if (!assignTo) {
response.setError(new sn_ws_err.BadRequestError('Assigned to ' + parsedData.assigned_to + ' not found'));
return;
}
// get the service sys id
function getBusinessService(serviceList) {
var affectedServices = [];
var sv = new GlideRecord('cmdb_ci_service_auto');
sv.addEncodedQuery("used_for=Production^x_nbapr_cloud_nat_service_idIN" + serviceList);
sv.query();
while (sv.next()) {
affectedServices.push(sv.sys_id.toString());
}
return affectedServices.toString();
}
// push the error to the field array and return error
function getInvalidFields() {
var fieldErrors = [];
if (!parsedData.description) {
fieldErrors.push('Missing required: description');
}
if (!parsedData.short_description) {
fieldErrors.push('Missing required: short_description');
}
if (!parsedData.business_service) {
fieldErrors.push('Missing required: services');
}
if (!parsedData.assignment_group) {
fieldErrors.push('Missing required: assignment_group');
}
if (!parsedData.assigned_to) {
fieldErrors.push('Missing required: assigned_to');
}
return fieldErrors;
}
gs.info("Testing endpoint" + body);
})(request, response);
Does that elaborate better?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 08:20 AM
You have to use below format(verify the field names);
var taskCIGR= new GlideRecord("task_ci");
taskCIGR.initialize();
taskCIGR.setValue("task","4c4148471bcdd51070fab99f034bcb40");
taskCIGR.setValue("ci","your_ci_sys_id");
taskCIGR.insert();
Similarly, for multiple sys_ids, create a for loop and insert in task_ci table
Aman Kumar