-
Notifications
You must be signed in to change notification settings - Fork 909
Hashtag & Mention Extractor (Regex) #2072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ivan-betev
wants to merge
10
commits into
ServiceNowDevProgram:main
from
ivan-betev:feature/new-regex
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aa77acf
Catalog Item Explorer - Widget Update
ivan-betev ed18c98
Update css.scss
ivan-betev 562f55d
Update script.js
ivan-betev 465b76d
Update client_script.js
ivan-betev 9f771b3
Update options_schema.json
ivan-betev 7b4a419
Merge branch 'ServiceNowDevProgram:main' into main
ivan-betev f47ea54
Create script.js
ivan-betev 32f3c77
Create README.md
ivan-betev 07826f2
Rename README.md to README.md
ivan-betev 6f2cc7f
Rename script.js to script.js
ivan-betev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Hashtag & Mention Extractor for ServiceNow | ||
|
|
||
| A simple yet useful **ServiceNow Background Script** that extracts all hashtags (`#example`) and mentions (`@user`) from any text input using regular expressions. | ||
|
|
||
| This script demonstrates how to apply JavaScript RegEx in server-side ServiceNow logic to parse, analyze, or extend user-generated text - ideal for text-analysis demos or lightweight automation projects. | ||
|
|
||
| --- | ||
|
|
||
| ## 💡 Example Use Cases | ||
| - Automatically identify hashtags and mentions in **incident comments**, **knowledge articles**, or **survey feedback**. | ||
| - Build internal analytics to track trending topics like `#VPN`, `#email`, or `#network`. | ||
ivan-betev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
| ## 🚀 How to Run | ||
| 1. In your ServiceNow instance, navigate to **System Definition → Scripts – Background**. | ||
| 2. Paste the script from this repository. | ||
| 3. Click **Run Script**. | ||
|
|
||
| --- | ||
|
|
||
| ## 📦 Reusability | ||
| The logic is **self-contained** within a single function block — no dependencies or external calls. | ||
| You can easily **copy and adjust it** to fit different contexts: | ||
| - Use it inside a **Business Rule**, **Script Include**, or **Flow Action Script**. | ||
ivan-betev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Replace the sample `demoData` with a field value (e.g., `current.comments`) to analyze live data. | ||
| - Adjust the regex to detect other patterns (emails, keywords, etc.). | ||
ivan-betev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| This makes it a **plug-and-play snippet** for any ServiceNow application or table that requires quick text pattern recognition. | ||
ivan-betev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
|
|
||
| ## 🔧 Possible Extensions | ||
| - Parse live table data (`sys_journal_field`, `kb_knowledge`) instead of static text. | ||
| - Store extracted tags in a custom table for analytics. | ||
| - Schedule a nightly “Top Tags” report with **Flow Designer** or **PA Widgets**. | ||
15 changes: 15 additions & 0 deletions
15
Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/script.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| (function() { | ||
|
|
||
| var demoData = "Quick test for hashtag and mention extraction in ServiceNow. " + | ||
| "Let's make sure it catches #Hack4Good #ServiceNow #regex and mentions like @ivan and @servicenow."; | ||
|
|
||
| var tagRegex = /[#@][A-Za-z0-9_]+/g; | ||
| var matches = demoData.match(tagRegex); | ||
ivan-betev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (matches && matches.length > 0) { | ||
| gs.info('Found ' + matches.length + ' tags: ' + matches.join(', ')); | ||
| } else { | ||
| gs.info('No hashtags or mentions found.'); | ||
| } | ||
|
|
||
| })(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.