-
Notifications
You must be signed in to change notification settings - Fork 907
Autofill from Recent Request #2206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0b98f2
Create Readme.md
Maheshkh9738 25c01a6
Create code snippet
Maheshkh9738 6a14da7
Update Readme.md
Maheshkh9738 20405e8
Update and rename code snippet to Auto fill script include
Maheshkh9738 8de0fd0
Create Client script Autofill
Maheshkh9738 b5e3bf4
Update Readme.md
Maheshkh9738 f52478c
Update Readme.md
Maheshkh9738 c9e3df1
Rename Client script Autofill to Client script Autofill.js
Maheshkh9738 f344a02
Rename Auto fill script include to Auto fill script include.JS
Maheshkh9738 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
30 changes: 30 additions & 0 deletions
30
... Script/Autofilling the request details from previous request/Auto fill script include.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,30 @@ | ||
| var GetRecentRequestValues = Class.create(); | ||
| GetRecentRequestValues.prototype = Object.extendsObject(AbstractAjaxProcessor, { | ||
| getValues: function() { | ||
| var userID = this.getParameter('sysparm_user'); | ||
| var itemID = this.getParameter('sysparm_item'); | ||
| var result = { found: false, values: {} }; | ||
|
|
||
| var gr = new GlideRecord('sc_req_item'); | ||
| gr.addQuery('requested_for', userID); | ||
| gr.addQuery('cat_item', itemID); | ||
| gr.orderByDesc('sys_created_on'); | ||
| gr.setLimit(1); | ||
| gr.query(); | ||
|
|
||
| if (gr.next()) { | ||
| result.found = true; | ||
|
|
||
|
|
||
| var vars = gr.variables; | ||
| result.values = { | ||
| 'requested_for': vars.requested_for + '', | ||
| 'location': vars.location + '', | ||
| 'department': vars.department + '' | ||
| }; | ||
| } | ||
|
|
||
| return JSON.stringify(result); | ||
| } | ||
| }); | ||
|
|
||
27 changes: 27 additions & 0 deletions
27
...nt Script/Autofilling the request details from previous request/Client script Autofill.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,27 @@ | ||
| function onLoad() { | ||
| var user = g_user.userID; | ||
| var itemID = g_form.getUniqueValue(); | ||
|
|
||
| var ga = new GlideAjax('GetRecentRequestValues'); | ||
| ga.addParam('sysparm_name', 'getValues'); | ||
| ga.addParam('sysparm_user', user); | ||
| ga.addParam('sysparm_item', itemID); | ||
| ga.getXMLAnswer(function(response) { | ||
| var data = JSON.parse(response); | ||
| if (data && data.found) { | ||
| var confirmFill = confirm("We found a similar request. Do you want to autofill fields?"); | ||
| if (confirmFill) { | ||
| for (var field in data.values) { | ||
| if (g_form.getControl(field)) { | ||
| g_form.setValue(field, data.values[field]); | ||
| console.log("Set " + field + " to " + data.values[field]); | ||
| } else { | ||
| console.log("Field not found: " + field); | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| console.log("No previous request found."); | ||
| } | ||
| }); | ||
| } |
10 changes: 10 additions & 0 deletions
10
...g Client Script/Autofilling the request details from previous request/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,10 @@ | ||
| Recent Request Autofill for ServiceNow Catalog.it automatically offers to fill in fields based on the user's most recent similar request. | ||
| Features | ||
| - Detects previous requests for the same catalog item | ||
| - Prompts user to reuse values from their last submission | ||
| - Autofills fields like location, department, and justification | ||
|
|
||
rohi-v marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <img width="878" height="395" alt="image" src="https://github.com/user-attachments/assets/33ceabf5-2bbc-43e3-8792-f1f9a99699d2" /> | ||
|
|
||
|
|
||
|
|
||
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.