
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2014 03:30 AM
Hi,
I'm sure that this is a simple enough script to write, but I am having one of those days where my brain is not working properly .
Basically, on our customer CMS homepage, I have created a news and Information iframe that displays messages such as service outages and service availability which is populated by Knowledge articles.
When an availability message is populated, I have created a field for remove time which is auto populated for 1 hour after the creation time. I have got a scheduled job to run a script that searches for the remove time and sets the article to retired. (similar to the autoclose incident script)
I have got another knowledge article called "All Systems Available", I want this to be automatically set to published when there are no other active knowledge articles, I cannot get a working script to do this.
I have got the below script to find the "All Systems Available" article, but not too sure I I can do a check to see if nothing else is pulblished: -
var xx = new GlideRecord("kb_knowledge"); xx.addQuery('sys_id','=','3738c071392095009bef8aa349ac8690'); xx.query(); while (xx.next()) { xx.workflow_state = 'published'; xx.update(); }
Can anyone help?
Thanks in advance,
Dan
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2014 03:59 AM
see if this works for you... ( obviously check field names to match your own setup/instance )
(function (options) {
function hasActiveArticles() {
var gr = new GlideRecord("kb_knowledge");
gr.addQuery("workflow_state", "published");
gr.addQuery("sys_id", "!=", options.article_id); // exclude "All Systems Available" article
gr.query();
return gr.getRowCount() > 0;
}
function enableMainArticle() {
if (!hasActiveArticles()) {
var gr = new GlideRecord("kb_knowledge");
if (gr.get(options.article_id)) {
gr.workflow_state = 'published';
gr.setWorkflow(options.stopBusinessRules);
gr.update();
}
}
}
// fire it off
enableMainArticle();
})({ article_id: "3738c071392095009bef8aa349ac8690", stopBusinessRules: true});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2014 03:59 AM
see if this works for you... ( obviously check field names to match your own setup/instance )
(function (options) {
function hasActiveArticles() {
var gr = new GlideRecord("kb_knowledge");
gr.addQuery("workflow_state", "published");
gr.addQuery("sys_id", "!=", options.article_id); // exclude "All Systems Available" article
gr.query();
return gr.getRowCount() > 0;
}
function enableMainArticle() {
if (!hasActiveArticles()) {
var gr = new GlideRecord("kb_knowledge");
if (gr.get(options.article_id)) {
gr.workflow_state = 'published';
gr.setWorkflow(options.stopBusinessRules);
gr.update();
}
}
}
// fire it off
enableMainArticle();
})({ article_id: "3738c071392095009bef8aa349ac8690", stopBusinessRules: true});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2014 04:53 AM
Hi Makosko,
Thank you very much for your response, I just had to change ">0" to "==0", other than that, it worked a treat,
Very much appreciated,
Thansk,
Dan