- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 09:51 AM
Hi All,
I need help, That I need a Business rule to change the Duplicate Knowledge article number into a new number.
Can any one help me
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:11 AM
To create a Business Rule in ServiceNow that changes the article number of a duplicate Knowledge article, you can follow these steps:
- Navigate to the Knowledge Base application in ServiceNow.
- Click on the "Business Rules" module in the left-hand navigation pane.
- Click on the "New" button to create a new Business Rule.
- Name the Business Rule something like "Change Duplicate Article Number".
- In the "When to Run" section, select "Before" from the dropdown menu.
- In the "Advanced" section, add a condition to check if the "number" field is already in use by another article. This can be done with a script similar to the following:
current.number.checkRecord(false);
if (current.number.nil() || current.number.hasChanged()) {
var articleGR = new GlideRecord('kb_knowledge');
articleGR.addQuery('number', current.number);
articleGR.query();
if (articleGR.next()) {
current.number = gs.generateGUID();
}
}
This script checks if the current Knowledge article's number field is already in use by another article, and if so, generates a new GUID and sets it as the article's new number.
- Save the Business Rule.
Note that this Business Rule will only run when a new Knowledge article is created or an existing one is updated, so it won't retroactively change the number of existing duplicate articles. Additionally, generating a new GUID as the article number may not be the best approach depending on your specific use case, so you may want to adjust the script accordingly.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:21 AM - edited 03-14-2023 10:22 AM
Hello @Priyanka16
You can run the below script and that should take care of all duplicate knowledge articles, and have them re-numbered.
You don't need to write any BR here.
You can simply copy this and run it on the background script module.
function fixDuplicates(num)
{
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('number', num);
gr.orderByDesc('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('incident');
gr.number = nm.getNextObjNumberPadded();
gr.update();
}
gs.print(gr.number);
}
If the script has solved your problem, then please mark the answer as solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:11 AM
To create a Business Rule in ServiceNow that changes the article number of a duplicate Knowledge article, you can follow these steps:
- Navigate to the Knowledge Base application in ServiceNow.
- Click on the "Business Rules" module in the left-hand navigation pane.
- Click on the "New" button to create a new Business Rule.
- Name the Business Rule something like "Change Duplicate Article Number".
- In the "When to Run" section, select "Before" from the dropdown menu.
- In the "Advanced" section, add a condition to check if the "number" field is already in use by another article. This can be done with a script similar to the following:
current.number.checkRecord(false);
if (current.number.nil() || current.number.hasChanged()) {
var articleGR = new GlideRecord('kb_knowledge');
articleGR.addQuery('number', current.number);
articleGR.query();
if (articleGR.next()) {
current.number = gs.generateGUID();
}
}
This script checks if the current Knowledge article's number field is already in use by another article, and if so, generates a new GUID and sets it as the article's new number.
- Save the Business Rule.
Note that this Business Rule will only run when a new Knowledge article is created or an existing one is updated, so it won't retroactively change the number of existing duplicate articles. Additionally, generating a new GUID as the article number may not be the best approach depending on your specific use case, so you may want to adjust the script accordingly.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:21 AM - edited 03-14-2023 10:22 AM
Hello @Priyanka16
You can run the below script and that should take care of all duplicate knowledge articles, and have them re-numbered.
You don't need to write any BR here.
You can simply copy this and run it on the background script module.
function fixDuplicates(num)
{
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('number', num);
gr.orderByDesc('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('incident');
gr.number = nm.getNextObjNumberPadded();
gr.update();
}
gs.print(gr.number);
}
If the script has solved your problem, then please mark the answer as solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 10:32 AM
Hi! I tried running this script and got this below & I still have the duplicates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 05:02 AM
Hi
This background script failed to do anything, any idea what is wrong with it? Could it be this line:
var nm = new NumberManager('incident');
Not sure what the logic is here