- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello All,
When user click on re-publish ui action to republish any article.
I want below things to work.
1. "valid to" to be extended based on Knowledge base validity when republished
2. Pre-populate a text in description stating "the article is re-published"
Can someone help how to achieve above scenarios.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Sriram28 ,
I tried your problem in my PDI and it works for me please check below solution
Navigate to UI Actions table and search for Republish and open kb_knowledge table button .
and add below script, I modified it as per your requirment
var newRecord = new KBKnowledge().republish(current);
if (newRecord) {
gs.addInfoMessage("Button Clicked");
var validTo = newRecord.getValue("valid_to");
gs.addInfoMessage(new KBKnowledge().getStateMessage(newRecord.getValue("workflow_state")));
action.setRedirectURL(newRecord);
var kbGR = new GlideRecord("kb_knowledge_base");
if (kbGR.get(current.kb_knowledge_base)) {
gs.addInfoMessage("InSide IF KB");
var validityDays = kbGR.getValue("article_validity");
// gs.addInfoMessage("validityDays = " + validityDays);
if (validityDays) {
gs.addInfoMessage("Inside IF Check = " + validityDays);
var now = new GlideDateTime();
now.addDays(validityDays);
gs.addInfoMessage("Now = " + now);
current.valid_to = now;
}
}
var msg = "This article has been re-published on " + gs.nowDateTime() + ".\n\n";
current.kb_description = msg + current.kb_description;
current.update();
} else
gs.addErrorMessage(gs.getMessage("You cannot republish this article. Please try again later."));
Result
My KB has validity as 20 days
So once I click the republish button it changes the date more then 20 days and also add description
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You can customize the republish UI action for KB articles by extending the script so that when a user clicks Republish it automatically recalculates the Valid to date (for example adding the base validity period from the Knowledge Base header) and sets the article short_description (or a custom field) to include text like (This article has been re published) before saving.......
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Technical Consultant - ServiceNow Class of Legends 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Sriram28 ,
I tried your problem in my PDI and it works for me please check below solution
Navigate to UI Actions table and search for Republish and open kb_knowledge table button .
and add below script, I modified it as per your requirment
var newRecord = new KBKnowledge().republish(current);
if (newRecord) {
gs.addInfoMessage("Button Clicked");
var validTo = newRecord.getValue("valid_to");
gs.addInfoMessage(new KBKnowledge().getStateMessage(newRecord.getValue("workflow_state")));
action.setRedirectURL(newRecord);
var kbGR = new GlideRecord("kb_knowledge_base");
if (kbGR.get(current.kb_knowledge_base)) {
gs.addInfoMessage("InSide IF KB");
var validityDays = kbGR.getValue("article_validity");
// gs.addInfoMessage("validityDays = " + validityDays);
if (validityDays) {
gs.addInfoMessage("Inside IF Check = " + validityDays);
var now = new GlideDateTime();
now.addDays(validityDays);
gs.addInfoMessage("Now = " + now);
current.valid_to = now;
}
}
var msg = "This article has been re-published on " + gs.nowDateTime() + ".\n\n";
current.kb_description = msg + current.kb_description;
current.update();
} else
gs.addErrorMessage(gs.getMessage("You cannot republish this article. Please try again later."));
Result
My KB has validity as 20 days
So once I click the republish button it changes the date more then 20 days and also add description
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago