- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 10:49 PM
I have a requirement when ever an Change is closed configuration item filed must not be empty.
How to write in fix script? I want only fix script
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 10:57 PM - edited 10-10-2022 11:12 PM
Hi Shashi,
If I correct you want to update configuration item field for closed change. once you run fix script whatever changes has empty CI it will get update with some value ? so you can refer below script
updateCI();
function updateCI(){
try{
var gr = new GlideRecord('change_request');
gr.addEncodedQuery('state=3^cmdb_ciISEMPTY'); // state is closed and ci is empty
gr.query();
while(gr.next()){
// your logic of updating here
gr.setValue('cmdb_ci','b0cb50c3c0a8000900893e69d3c5885e');
gr.update();
}
}
catch(ex){
gs.info(ex);
}
}
Kindly mark response correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 11:25 PM
Hi Sai,
I want to apply new validation to restrict the users from should notclosing the change without ci
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 11:21 PM
Hello,
Please use the below code in your fix script. Once you run this all the closed change request will have the configuration item field emptied.
var cr = new GlideRecord('change_request');
cr.addEncodedQuery('state=3');
cr.query();
while (cr.next()) {
cr.cmdb_ci='';
cr.update();
cr.setWorkflow(false);
}
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 11:26 PM
If CI is empty then the Change should not close
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 11:35 PM
In our script we are only changing the CI's of the CR which are already closed so we are not closing any change so you no need to worry.
Please mark my answer as correct based on Impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 11:50 PM
Hi,
Below code prints all the Change Requests where state is closed and CI is empty. To add restrictions you should use UI Policy
var gr = new GlideRecord("change_request");
gr.addQuery("state", "3");
gr.addNotNullQuery("cmdb_ci");
gr.query();
while (gr.next()) {
gs.info(gr.number);
}
Palani