
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 07:04 AM
Hi All,
Good Day!
I was asked to the below requirement and as my task doesn't mainly include scripting I'm trying to process what is being asked here:
- Create a new function called ChangeManagementUtil called "isContainsRetiredCIs" which accepts the change request as the parameter:
- This will be query the task_ci table and returns false if the CI's operational status is Retired, otherwise return true.
I have done the below script but it doesn't seem to be working and I'm not sure if I'm on the right path to achieve the above requirement.
isContainsRetiredCIs: function(change_request) {
var taskGR = new GlideRecord('task_ci');
taskGR.addQuery('operational_status');
taskGR.query();
while (taskGR.next()) {
if(taskGR.operational_status != 'Retired'){
taskGR.isValidRecord();
};
},
Also can you please advise as to how I can test it using the background script app? Since currently what I do is I save this script include update and go to the change_request table > Add an Affected CIs to see if it's working. The goal here is to make sure the Retires CIs and affected CIs can't be selected in a change request. Appreciate your asistance on this!
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 08:29 AM
Hi,
Value of Retired is 6. So, in your code you can query whether Operational status is not 6.
isContainsRetiredCIs: function(change_request) {
var taskGR = new GlideRecord('task_ci');
taskGR.addQuery('task',change_request); // Use this line if change_request has sys_id. If it has Change Number then comment this line and uncomment next line
//taskGR.addQuery('task.number',change_request);
taskGR.addEncodedQuery('ci_item.operational_status!=6'); // Check if operational status is not retired
taskGR.query();
return taskGR.hasNext(); // Return true if record returned. Otherwise return false
};
},
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 07:13 AM
Hi,
You code should be like this:
Note: Read the comment in line 3 and update code accordingly
isContainsRetiredCIs: function(change_request) {
var taskGR = new GlideRecord('task_ci');
taskGR.addQuery('task',change_request); // Use this line if change_request has sys_id. If it has Change Number then comment this line and uncomment next line
//taskGR.addQuery('task.number',change_request);
taskGR.addQuery('ci_item.operational_status','1'); // Check if operational status is Operational
taskGR.query();
return taskGR.hasNext(); // Return true if record returned. Otherwise return false
};
},
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 07:48 AM
Hi
Thank you for your help, I just have a question as per my requirement it has to return true if the operational status is operational, non-operational, ready etc. (all status except retired) and should return false if the operational status is Retired. How should I achieve this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 08:16 AM
This would do that...
function change_request) {
return new global.GlideQuery('task_ci')
.getBy({
'task': change_request,
'ci_item.operational_status': 6
}).isEmpty();
},
This also returns true if no task_ci record is found for that change_request, if that is not the desired behaviour it will need a tweak.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 08:29 AM
Hi,
Value of Retired is 6. So, in your code you can query whether Operational status is not 6.
isContainsRetiredCIs: function(change_request) {
var taskGR = new GlideRecord('task_ci');
taskGR.addQuery('task',change_request); // Use this line if change_request has sys_id. If it has Change Number then comment this line and uncomment next line
//taskGR.addQuery('task.number',change_request);
taskGR.addEncodedQuery('ci_item.operational_status!=6'); // Check if operational status is not retired
taskGR.query();
return taskGR.hasNext(); // Return true if record returned. Otherwise return false
};
},
Palani