- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 12:49 AM - edited 11-13-2023 01:01 AM
hello All,
we need to Remove an XYZ criteria from knowledge block in Bulk , if we have 4 to 5 criteria's to single block we need to Just remove XYZ alone and we need to keep other Criterias as it is
I have used this logic but it is removing all criteria's
var gr = new GlideRecord('kb_knowledge_block');
gr.addEncodedQuery('kb_knowledge_base=ab0372fb1b668914619fed79b04bcba6^can_read_user_criteriaLIKE070120ae1b35695072e6eb99bd4bcb2a');
gr.query();
while (gr.next()) {
gs.info(gr.getRowCount());
gr.setValue('can_read_user_criteria','')
gr.update();
}
@Ankur Bawiskar @Sandeep Rajput @jaheerhattiwale @Pavankumar_1
can you please correct the script just remove only xyz from block
TIA
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 04:12 AM
update as this
var gr = new GlideRecord('kb_knowledge_block');
gr.addEncodedQuery('kb_knowledge_base=ab0372fb1b668914619fed79b04bcba6^can_read_user_criteriaLIKE070120ae1b35695072e6eb99bd4bcb2a');
gr.query();
while (gr.next()) {
var arr = gr.can_read_user_criteria.toString().split(',');
var index = arr.indexOf('070120ae1b35695072e6eb99bd4bcb2a');
if (index > -1) { // only splice array when item is found
arr.splice(index, 1); // 2nd parameter means remove one item only
}
gr.setValue('can_read_user_criteria', arr.toString());
gr.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 03:12 AM
Thank you but criteria might not be always at index(1) , it can be at diff index's as well , can you correct me if am wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 03:32 AM
Hi @Michael51 ,
That 1 indicates how many values u want to remove. Hence 1.
You can check below link for reference :
https://www.w3schools.com/jsref/jsref_splice.asp
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 03:47 AM
Hello @Danish Bhairag2 ,
this is not working , it is not removing the criteria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 03:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 04:13 AM
Hi @Michael51 ,
Can u just try checking for 1 record ?
you can apply logs n verify wht values it is returning?
u can try it in background script
var commaValues = [];
var gr = new GlideRecord('kb_knowledge_block');
gr.addEncodedQuery('kb_knowledge_base=ab0372fb1b668914619fed79b04bcba6^can_read_user_criteriaLIKE070120ae1b35695072e6eb99bd4bcb2a');
gr.query();
while (gr.next()) {
var val = gr.can_read_user_criteria.toString();
commaValues = val.split(',');
var index = commaValues.indexOf('070120ae1b35695072e6eb99bd4bcb2a');
var x = commaValues.splice(index, 1);
gs.info("Final Value:- "+ commaValues);
gr.can_read_user_criteria = commaValues.join(',');
gr.update();
}
Check the final value log whether it returns the proper output
Thanks,
Danish