Need to override KBCommonSNC review message "This knowledge item is in review" with custom message

RajeshkumarV
Tera Contributor

Hi All,

Need to override

getStateMessage - review message "This knowledge item is in review" which is available in script include -KBCommonSNC  with custom message.
I have already tried gs.flushMessage() to suppress OOTB message in business rule, but it didn't work. 
And KBCommonSNC mentioned as high priority file, so I am bit hesitating to edit it.
 
Any help is much appreciated. Thank you.
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@RajeshkumarV 

try this

  1. Create a Custom Script Include:

    • Navigate to System Definition > Script Includes.
    • Click on New to create a new script include.
    • Name it something like CustomKBCommonSNC.
    • Extend the KBCommonSNC class.
  2. Override the getStateMessage Method:

    • In your custom script include, override the getStateMessage method to return your custom message.

Here's an example of how you can do this:

var CustomKBCommonSNC = Class.create();
CustomKBCommonSNC.prototype = Object.extendsObject(KBCommonSNC, {
    getStateMessage: function(state) {
        if (state == 'review') {
            return "Your custom review message here";
        }
        return this._super(state);
    }
});
  1. Update the Business Rule:
    • Ensure your business rule calls the custom script include instead of the original KBCommonSNC.
var customKBCommon = new CustomKBCommonSNC();
var message = customKBCommon.getStateMessage(current.state);
gs.addInfoMessage(message);

This way, you avoid directly modifying the high-priority KBCommonSNC script include and still achieve the desired customization.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@RajeshkumarV 

try this

  1. Create a Custom Script Include:

    • Navigate to System Definition > Script Includes.
    • Click on New to create a new script include.
    • Name it something like CustomKBCommonSNC.
    • Extend the KBCommonSNC class.
  2. Override the getStateMessage Method:

    • In your custom script include, override the getStateMessage method to return your custom message.

Here's an example of how you can do this:

var CustomKBCommonSNC = Class.create();
CustomKBCommonSNC.prototype = Object.extendsObject(KBCommonSNC, {
    getStateMessage: function(state) {
        if (state == 'review') {
            return "Your custom review message here";
        }
        return this._super(state);
    }
});
  1. Update the Business Rule:
    • Ensure your business rule calls the custom script include instead of the original KBCommonSNC.
var customKBCommon = new CustomKBCommonSNC();
var message = customKBCommon.getStateMessage(current.state);
gs.addInfoMessage(message);

This way, you avoid directly modifying the high-priority KBCommonSNC script include and still achieve the desired customization.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader