Background Script to Retire CI's and remove relationship of CI's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 05:24 AM
Hi Experts,
Can anyone please help me to write a Background/Fix script: Below is the requirement. Kindlty help
1. If the "Most recent discovery" is before 3 days from present date:
2. then we have to remove the service offerings (Relationship type: Contained By) and mapped application services (Relationship type: Used By) which are related to the application server:
3. Make the "STATUS" and "OPERATIONAL STATUS" as "RETIRED":
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 05:43 AM
Hello ,
Can you try this once.
var grRel = new GlideRecord('cmdb_rel_ci'); //relationship table
var gr = new GlideRecord('cmdb_ci'); //ci table
gr.addEncodedQuery('Your Query');
gr.query();
while (gr.next){
//add query on relationship table
grRel.addEncodedQuery('type=contained by^ORtype=usedby^parent=' + gr.parent); //Parent or child its up to you
while(grRel.next()){
grRel.parent ='';
//or
grRel.child='';
gr.status ='retired';
gr.operational_status = 'retired';
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 03:41 AM
Hi Vishal,
Thanks for your response. The thing is if a CI that is going to be retired is having another CI in the relationship then that CI's should also be checked wether it have any relations and then we need to retire that CI's and then we need to retire the main CI. I am really confused and seeking the help.
We need to build a script may be a schedule job as per the instrauctions given in the attached word document. The instructions given in the word document are done manually by users, now they are requesting for a script as they are getting many CI's in bulk to retire.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2022 09:48 AM
We actually do alot of this work in this post, update sets and all...