- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2014 07:06 AM
I am needing to add a specific role to all of our 4,500 knowledge articles, however, I am prevented from editing the "Role" field when viewing these articles in List view.
That was the fastest way I could think to update them all - anyone else have some different ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2014 02:21 AM
The roles field in Knowledge [kb_knowledge] table is glide_list type which is restricted for list editing OOTB (there is a property for it called "glide.ui.list_edit_ignore_types"). Definitely better option how to update all these records is to use the background script (module "Scripts - Background"). So I think you should run a script similar to this one:
var roleName = 'test'; // name of the role to be added
var knowledgeGR = new GlideRecord('kb_knowledge');
// add more specific condition if you want to update only selected articles
// without any condition it will update all articles
knowledgeGR.query();
while (knowledgeGR.next()) {
var current = knowledgeGR.getValue('roles');
if (gs.nil(current)) {
knowledgeGR.roles = roleName;
} else {
// there should be check if the role is already there and if so then it should not be added
knowledgeGR.roles = current + ',' + roleName;
}
knowledgeGR.setWorkflow(false); // not run business rules
knowledgeGR.setUseEngines(false);
knowledgeGR.autoSysFields(false); // not update Updated on and Updated by fields
knowledgeGR.update();
}
This example script can help you create the script that you need in your case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2014 03:47 PM
I'd just do it in a background script. Since it's a reference, you'll need to set the field to the sys_id of the role. If it's a field that allows MULTIPLE roles and you want to keep the current values, then your script will have to be more complex.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2014 02:21 AM
The roles field in Knowledge [kb_knowledge] table is glide_list type which is restricted for list editing OOTB (there is a property for it called "glide.ui.list_edit_ignore_types"). Definitely better option how to update all these records is to use the background script (module "Scripts - Background"). So I think you should run a script similar to this one:
var roleName = 'test'; // name of the role to be added
var knowledgeGR = new GlideRecord('kb_knowledge');
// add more specific condition if you want to update only selected articles
// without any condition it will update all articles
knowledgeGR.query();
while (knowledgeGR.next()) {
var current = knowledgeGR.getValue('roles');
if (gs.nil(current)) {
knowledgeGR.roles = roleName;
} else {
// there should be check if the role is already there and if so then it should not be added
knowledgeGR.roles = current + ',' + roleName;
}
knowledgeGR.setWorkflow(false); // not run business rules
knowledgeGR.setUseEngines(false);
knowledgeGR.autoSysFields(false); // not update Updated on and Updated by fields
knowledgeGR.update();
}
This example script can help you create the script that you need in your case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2014 05:12 AM
This script worked great! Thank you so much.