- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 08:19 AM
All our Valid To dates are the default 1/1/2020 and am looking to clean this up. What is the best way to set the Valid To date of all KB articles with an Updated date before Jan 2017 to a year after the Updated date?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 09:23 AM
Hi,
For your specific requirement, You can run this script in the background.
var kb = new GlideRecord('kb_knowledge');
kb.addEncodedQuery('sys_updated_on<=javascript:gs.endOfLastYear()'); //Fetches all records before last year
kb.query();
while(kb.next()){
var gdt = new GlideDateTime(kb.sys_updated_on.toString()); //Gets the last updated date
gdt.addYearsUTC(1) //Adds One year to it
kb.setWorkflow(false);
kb.valid_to = gdt.getDate(); //Sets valid to as one year + last updated date
kb.update();
}
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 08:45 AM
HI,
For bulk updates you can use Background Scripts to update your Valid to Date field from backend. Below Link may be useful:
http://www.servicenowelite.com/blog/2014/1/17/how-to-use-background-scripts
To use Background script you need to first enable the elevated Privileges and then navigate to Background Script as shown below:
You can use the below script for reference:
Script:
var gr = new GlideRecord('kb_knowledge');
var string='numberINKB0010051,KB0010052'; //Replace your query with appropriate Knowledge Numbers
gr.addEncodedQuery(string)
gr.query();
while(gr.next())
{
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.valid_to= '2018-02-28';
gr.update();
}
Note: Try running Background script in some Sub Production instances like Dev instance before running it in Production
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 09:23 AM
Hi,
For your specific requirement, You can run this script in the background.
var kb = new GlideRecord('kb_knowledge');
kb.addEncodedQuery('sys_updated_on<=javascript:gs.endOfLastYear()'); //Fetches all records before last year
kb.query();
while(kb.next()){
var gdt = new GlideDateTime(kb.sys_updated_on.toString()); //Gets the last updated date
gdt.addYearsUTC(1) //Adds One year to it
kb.setWorkflow(false);
kb.valid_to = gdt.getDate(); //Sets valid to as one year + last updated date
kb.update();
}
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2019 08:58 AM
You should be able to simply get your articles that need updating in a list view, bring in the 'valid to date' from the cog and select the articles, right click and update the date in bulk to what you need.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2020 09:48 AM
I didn't get the answer I was hoping to see, but I did figure it out on my own. I'm documenting it here in case anyone else comes across this and doesn't want to run scripts or mess with client scripts or custom code.
Previously, we did not have Knowledge Advanced enabled, so this was an easy task to do before as a mass edit from the list view of Knowledge All. Since we enabled Knowledge Advanced and the respective versioning feature, however, the required checkout option activated some client scripts that prevent fields from being edited without checkout and read-only on the list and form views. I had to make a few changes to be able to edit articles from the list view, but it was fairly easy once I figured it out. Here are the steps I took to successfully update multiple articles' "Valid to" dates (and can be used for any Knowledge field as well):
We first need to change the default list control setting to enable list editing on all KB articles.
1. From the Filter Navigator, navigate to Knowledge > Articles > All.
2. Right-click on any header column in the list and select Configure > List Control.
3. On the kb_knowledge form, in the List edit type field, select "Save immediately (cell edit mode)" and click Update.
Now that the list is editable, we need to allow specific fields to not require checkout in order to be edited. In order to make specific fields not read-only, we need to change a Knowledge property.
4. Navigate to Knowledge > Administration > Properties.
5. Scroll down near the bottom of the page to the "Article Versioning Properties" section. Again, these are steps for Knowledge if you have the Knowledge Advanced plugin enabled. If you do not, I believe you can stop here and be able to edit the list as you see fit.
6. If the "Enable article versioning feature." option is selected, that is the option that requires KB articles to be checked out, otherwise they appear as read-only. We do not need to change this setting. This is probably the reason you have Knowledge Advanced even enabled. Instead, select the option to "Enable minor edits to the published article without creating a new version."
7. Under the last option in that section, "List of fields (comma-separated) that can be edited on published articles without creating a new version." make sure "valid_to" is listed as a field (it was already populated in my instance, but the minor edits option was not enabled by default). If you want to add additional fields to be edited without checkout, this is where those should be added as well.
8. Click Save.
ServiceNow will now allow the "Valid to" field to be edited from either the form or list view, without requiring checkout. I personally sort the Knowledge All by "Valid to" date ascending, with view blocks of 100. I also filter by workflow, since I'm only concerned with updating those articles in draft or published states. In order to not inundate the system, I also filter by date ranges, so I only update chunks of articles at a time (I found 1000 records at a time updated in less than 60 seconds). I also utilize the Update All list function by right-clicking the header column and selecting Update All. This will display a prompt letting you know how many rows will be affected by the update. Click OK. This navigates to a form where the only field I modify is the "Valid to" field. Remember that any field you modify on this form will update ALL articles that you have selected. Once you are comfortable with the change, click Update.
Hope this helps someone who is struggling with Knowledge Advanced.