
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 12:02 PM - edited 04-19-2023 12:02 PM
We have a task :
>>validate all certs in sys_certificate
>>if If any errors occur during the validation, either mark the "Active" checkbox as false/disable
What is the code to achieve this. thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 12:35 PM - edited 04-19-2023 12:39 PM
You can run the following background script to check if the certificates are valid, I recommend running in a sub-production environment first of course:
var gr = new GlideRecord('sys_certificate');
gr.addEncodedQuery('expires_in_days>0');
gr.query();
while(gr.next()){
var valid = new SNC.CertificateValidator().validate(gr);
if(!valid){
gs.info("Certificate for "+gr.getValue('name')+" = VALID");
gr.setValue('active', true);
}else{
gs.info("Certificate for "+gr.getValue('name')+" = INVALID");
gr.setValue('active', false);
}
gr.update();
}
This uses the CertificateValidator API which is the same API used for the UI Action "Validate Stores/Certificates" on the sys_certificate table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 12:35 PM - edited 04-19-2023 12:39 PM
You can run the following background script to check if the certificates are valid, I recommend running in a sub-production environment first of course:
var gr = new GlideRecord('sys_certificate');
gr.addEncodedQuery('expires_in_days>0');
gr.query();
while(gr.next()){
var valid = new SNC.CertificateValidator().validate(gr);
if(!valid){
gs.info("Certificate for "+gr.getValue('name')+" = VALID");
gr.setValue('active', true);
}else{
gs.info("Certificate for "+gr.getValue('name')+" = INVALID");
gr.setValue('active', false);
}
gr.update();
}
This uses the CertificateValidator API which is the same API used for the UI Action "Validate Stores/Certificates" on the sys_certificate table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 12:44 PM
Thanks, this is for sub prod only 🙂
I will test and update, thank you for the prompt response