-
Notifications
You must be signed in to change notification settings - Fork 908
Auto add watch list based on caller #2231
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
Indra-kolge
wants to merge
3
commits into
ServiceNowDevProgram:main
from
Indra-kolge:Auto-Add-Watch-List-Based-on-Caller
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
16 changes: 16 additions & 0 deletions
16
Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ClientScript.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,16 @@ | ||
| function onChange(control, oldValue, newValue, isLoading) { | ||
| if (isLoading || !newValue) return; | ||
|
|
||
| // GlideAjax call to fetch department leads | ||
| var ga = new GlideAjax('WatchListHelper'); | ||
| ga.addParam('sysparm_name', 'getWatchListByCaller'); | ||
| ga.addParam('sysparm_caller', newValue); | ||
| ga.getXMLAnswer(function(answer) { | ||
| if (answer) { | ||
| // answer is comma separated list of sys_ids | ||
| var currentWatchList = g_form.getValue('watch_list'); | ||
| var combined = currentWatchList ? currentWatchList + ',' + answer : answer; | ||
| g_form.setValue('watch_list', combined); | ||
| } | ||
| }); | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
...nt-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/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,15 @@ | ||
|
|
||
| Auto-Add Watch List Based on Caller Department | ||
|
|
||
| //Use Case : | ||
|
|
||
| Automatically adds relevant users to the Watch List field when a Caller is selected on Incident. | ||
| Keep department leads or stakeholders automatically informed. | ||
|
|
||
| //Logic: | ||
|
|
||
| Client Script runs onChange of the Caller field. | ||
| Calls a Client callable Script Include ('WatchListHelper) via GlideAjax. | ||
| Script Include fetches Department manager | ||
| Adds their sys_id to the Watch List field. | ||
| Prevents duplicates by appending to existing watch list values. |
21 changes: 21 additions & 0 deletions
21
Client-Side Components/Client Scripts/Auto-Add Watch List Based on Caller/ScriptInclude.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,21 @@ | ||
| var WatchListHelper = Class.create(); | ||
| WatchListHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, { | ||
|
|
||
| getWatchListByCaller: function() { | ||
| var callerId = this.getParameter('sysparm_caller'); | ||
| var watchListSysIds = []; | ||
| var userGR = new GlideRecord('sys_user'); | ||
| if (userGR.get(callerId) && userGR.department) { | ||
| // Fetch department managers | ||
| var dept = new GlideRecord('cmn_department'); | ||
| if (dept.get(userGR.department)) { | ||
| if (dept.manager) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Department table doesn't have manager field OOTB. |
||
| watchListSysIds.push(dept.manager.sys_id.toString()); | ||
| } | ||
| } | ||
| // Return as comma separated string | ||
| return watchListSysIds.join(','); | ||
| }, | ||
|
|
||
| type: 'WatchListHelper' | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.