Auto create announcement when outage created

Bidduam
Tera Guru

I would like to have a portal announcement created when an outage is created. I don't really care if it is automatic or requires some other prompt, like if a checkbox is selected on the outage form then create an announcement for example.

 

I figure a business rule or an event might be the way to go, but I really have no idea how to start either as when I choose a table, I have no idea how to link to the other table - announcement or outage.

 

I'd also want the end date being added to the outage to auto de activate the announcement.

 

I've already found this previous question, but it is not at all helpful:

Creating Announcements from Outages

 

If you have an idea can you also please include some details - I won't know how to go further without at least a bit of a start.

 

Thanks

1 ACCEPTED SOLUTION

Sorry My bad,

Create 2 BR,

For Update :-

GunjanKiratkar_0-1668586920778.png

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("announcement");
    gr.addEncodedQuery("active=true^nameLIKE"+current.number);
    gr.query();
    if (gr.next()) {
		gr.to=current.end;
		gr.update();
    }


})(current, previous);

 

For Insert :-

BR only after Insert

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("announcement");
    gr.initialize();
    gr.name = 'Outage Number' + current.number + ' created.';
    gr.title = 'Outage For' + current.getDisplayValue('cmdb_ci') + ' is created.';
    gr.summary = current.short_description;
    gr.active = 'true';
    gr.from = new GlideDateTime();
    gr.insert();


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

5 REPLIES 5

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Bidduam ,

You can writedown after insert Business rule on cmdb_ci_outage table as below 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("announcement");
    gr.initialize();
    gr.name = 'Outage Number' + current.number + ' created.';
    gr.title = 'Outage For' + current.getDisplayValue('cmdb_ci') + ' is created.';
    gr.summary = current.short_description;
    gr.active = 'true';
    gr.from = new GlideDateTime();
    gr.update();


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

@Gunjan Kiratkar that is awesome thank you.

 

Do you have any ideas on how to close the announcement once the outage is ended? Just by adding the end date in the outage record

Hi @Bidduam ,

yes then make your BR after Update/Insert and make below changes

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("announcement");
    gr.initialize();
    gr.name = 'Outage Number' + current.number + ' created.';
    gr.title = 'Outage For' + current.getDisplayValue('cmdb_ci') + ' is created.';
    gr.summary = current.short_description;
    gr.active = 'true';
    gr.from = new GlideDateTime();
    if(current.end!=''){
    gr.to=current.end;
    }
    gr.insert();


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Sorry My bad,

Create 2 BR,

For Update :-

GunjanKiratkar_0-1668586920778.png

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("announcement");
    gr.addEncodedQuery("active=true^nameLIKE"+current.number);
    gr.query();
    if (gr.next()) {
		gr.to=current.end;
		gr.update();
    }


})(current, previous);

 

For Insert :-

BR only after Insert

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("announcement");
    gr.initialize();
    gr.name = 'Outage Number' + current.number + ' created.';
    gr.title = 'Outage For' + current.getDisplayValue('cmdb_ci') + ' is created.';
    gr.summary = current.short_description;
    gr.active = 'true';
    gr.from = new GlideDateTime();
    gr.insert();


})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy