- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 12:13 PM
Hello,
On the problem table there is a field called known error which is true/false. I am trying to set this for records where a Knowledge Article was created in the KE Knowledge Base. Any assistance would be appreciated. Thanks!
var knowledge = new GlideRecord('kb_knowledge');
knowledge.addEncodedQuery("source.sys_class_name=problem^kb_knowledge_base=e33ab413dbfe16401c76d9fdbf96194a");
knowledge.query();
while(knowledge.next()){
var problem = new GlideRecord('problem');
problem.get(knowledge.problem.syd_id);
while(problem.next()){
problem.setValue ('known_error', true);
problem.update();
}
}
Solved! Go to Solution.
- Labels:
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 12:26 PM
You can try this script. I've commented the 'update' at the end out so that you can test and see that you're getting the right stuff. Run it from 'Scripts -> Background' to see what the output is and make sure you're getting the correct items before actually doing the update.
var knowledge = new GlideRecord('kb_knowledge');
knowledge.addEncodedQuery("source.sys_class_name=problem^kb_knowledge_base=e33ab413dbfe16401c76d9fdbf96194a");
knowledge.query();
gs.print('Knowledge article count: ' + knowledge.getRowCount());
while(knowledge.next()){
var problem = new GlideRecord('problem');
problem.addQuery('sys_id', knowledge.source.syd_id);
problem.query();
gs.print('Problem count should equal KB count: ' + problem.getRowCount());
while(problem.next()){
problem.setValue('known_error', true);
problem.setWorkflow(false); // Don't run business rules, etc.
problem.autoSysFields(false); // Don't update system fields
//problem.update();
gs.print('Problem: ' + problem.number);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 12:26 PM
You can try this script. I've commented the 'update' at the end out so that you can test and see that you're getting the right stuff. Run it from 'Scripts -> Background' to see what the output is and make sure you're getting the correct items before actually doing the update.
var knowledge = new GlideRecord('kb_knowledge');
knowledge.addEncodedQuery("source.sys_class_name=problem^kb_knowledge_base=e33ab413dbfe16401c76d9fdbf96194a");
knowledge.query();
gs.print('Knowledge article count: ' + knowledge.getRowCount());
while(knowledge.next()){
var problem = new GlideRecord('problem');
problem.addQuery('sys_id', knowledge.source.syd_id);
problem.query();
gs.print('Problem count should equal KB count: ' + problem.getRowCount());
while(problem.next()){
problem.setValue('known_error', true);
problem.setWorkflow(false); // Don't run business rules, etc.
problem.autoSysFields(false); // Don't update system fields
//problem.update();
gs.print('Problem: ' + problem.number);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2018 12:54 PM
Hello Mark,
This worked 99% I had to tweek the problem addQuery to use the number field instead of the sys_id. Thanks for your assistance!
Chad