Custom UI action button in Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have created the UI action button as close_rejected for Knowledge Mgmt. When the Knowledge Article comes to review for Knowledge Manager and he finds that KA is not good enough so he can reject the article and no one one can action on that. I have created below Server side script for this UI action . Knowledge article moving to close_rejected state but only in draft stage and not in other stage. also Knowledge article is not moving in read only when I am clicking on close_rejected. I have created Client side On Load script to move the form to read only. Also I am trying through UI Policy where I am putting the condition as workflow is close_rejected and then creating UI action for all the field in the form to make them read only. Please assist how to resolve this issue. backend Value of workflow choice - close_rejected
UI Policy action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @akchauhan ,
/ Server-side Script for UI Action
(function executeAction(current, action) {
// Only proceed if not already in close_rejected
if (current.workflow_state !== 'close_rejected') {
current.workflow_state = 'close_rejected';
// Optional: Set article state if you use a separate field
// current.article_state = 'rejected';
current.update();
gs.addInfoMessage("This knowledge article has been closed as rejected and is now read-only.");
} else {
gs.addInfoMessage("This knowledge article is already in the rejected state.");
}
action.setRedirectURL(current);
})(current, action);
Client script on Load to move the form to read only
function onLoad() {
var state = g_form.getValue('workflow_state');
if (state === 'close_rejected') {
var fields = g_form.getFieldNames();
for (var i = 0; i < fields.length; i++) {
// Optionally skip mandatory system fields like sys_id, etc.
if (fields[i] !== 'sys_id') {
g_form.setReadOnly(fields[i], true);
}
}
}
}
Thanks
Santosh.p
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
so what's not working?
what debugging did you do?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Dear Ankur,
As I have mentioned above that I have tried client script, UI policy and even Business rule also I have applied to run this UI action button. but nothing working for me and moreover this is first time to get into this kind of issues . hence not able to understand what went wrong. Please assist.