- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2017 05:56 AM
Hi all,
I'm after some assistance with a background script that i'm trying to get to work. I have a list of knowledge categories and i'm trying to bulk replace the word Dashboards with Analytics.
The field is a string field and i get the following list when running my background script query.
*** Script: KB: Dashboards / Dashboards / Connectivity
*** Script: KB: Dashboards / Dashboards / Other / General questions
*** Script: KB: Dashboards / Dashboards / Security / Remove Access
*** Script: KB: Dashboards / Dashboards / Connectivity / Access Issues
*** Script: KB: Dashboards / Dashboards / Other
*** Script: KB: Dashboards / Dashboards / Security / Access Issues
*** Script: KB: Dashboards / Dashboards / Security / New Access Request
*** Script: KB: Dashboards / Dashboards / Security
*** Script: KB: Dashboards / Dashboards
I have the following script. I have amended line 6 a few times to try different things, but cannot get it to update.
grCI = new GlideRecord('kb_category');
grCI.addQuery('full_category','STARTSWITH','Dashboards / D');
grCI.query();
while (grCI.next()){
gs.print('KB: '+grCI.full_category);
grCI.full_category = grCI.full_category.replace(/Dashboard/g , "Analytics");
grCI.update;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2017 06:21 AM
Got it to work, was missing () after the word update on line 7
grCI = new GlideRecord('kb_category');
grCI.addQuery('full_category','STARTSWITH','Dashboards / D');
grCI.query();
while (grCI.next()){
gs.print('KB 1: '+grCI.full_category);
grCI.full_category = grCI.full_category.replace(/Dashboards/g , "Analytics");
gs.print('KB 2: '+grCI.full_category);
grCI.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2019 05:37 AM
Can you please explain the use /D and /g in the above script for quering and replacing
?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2021 11:09 PM
/g modifier is Global search:
https://www.w3schools.com/jsref/jsref_regexp_g.asp
/D is non digit characters
https://www.w3schools.com/jsref/jsref_regexp_digit_non.asp
However, looking at his specific case, I think he's simply trying to match the name at the start of the string ie:
Dashboards / Dashboards / Connectivity
==
"Dashboards / D"ashboards / Connectivity