File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
Client-Side Components/Catalog Client Script/Autofilling the request details from previous request Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ var GetRecentRequestValues = Class . create ( ) ;
2+ GetRecentRequestValues . prototype = Object . extendsObject ( AbstractAjaxProcessor , {
3+ getValues : function ( ) {
4+ var userID = this . getParameter ( 'sysparm_user' ) ;
5+ var itemID = this . getParameter ( 'sysparm_item' ) ;
6+ var result = { found : false , values : { } } ;
7+
8+ var gr = new GlideRecord ( 'sc_req_item' ) ;
9+ gr . addQuery ( 'requested_for' , userID ) ;
10+ gr . addQuery ( 'cat_item' , itemID ) ;
11+ gr . orderByDesc ( 'sys_created_on' ) ;
12+ gr . setLimit ( 1 ) ;
13+ gr . query ( ) ;
14+
15+ if ( gr . next ( ) ) {
16+ result . found = true ;
17+
18+
19+ var vars = gr . variables ;
20+ result . values = {
21+ 'requested_for' : vars . requested_for + '' ,
22+ 'location' : vars . location + '' ,
23+ 'department' : vars . department + ''
24+ } ;
25+ }
26+
27+ return JSON . stringify ( result ) ;
28+ }
29+ } ) ;
30+
Original file line number Diff line number Diff line change 1+ function onLoad ( ) {
2+ var user = g_user . userID ;
3+ var itemID = g_form . getUniqueValue ( ) ;
4+
5+ var ga = new GlideAjax ( 'GetRecentRequestValues' ) ;
6+ ga . addParam ( 'sysparm_name' , 'getValues' ) ;
7+ ga . addParam ( 'sysparm_user' , user ) ;
8+ ga . addParam ( 'sysparm_item' , itemID ) ;
9+ ga . getXMLAnswer ( function ( response ) {
10+ var data = JSON . parse ( response ) ;
11+ if ( data && data . found ) {
12+ var confirmFill = confirm ( "We found a similar request. Do you want to autofill fields?" ) ;
13+ if ( confirmFill ) {
14+ for ( var field in data . values ) {
15+ if ( g_form . getControl ( field ) ) {
16+ g_form . setValue ( field , data . values [ field ] ) ;
17+ console . log ( "Set " + field + " to " + data . values [ field ] ) ;
18+ } else {
19+ console . log ( "Field not found: " + field ) ;
20+ }
21+ }
22+ }
23+ } else {
24+ console . log ( "No previous request found." ) ;
25+ }
26+ } ) ;
27+ }
Original file line number Diff line number Diff line change 1+ Recent Request Autofill for ServiceNow Catalog.it automatically offers to fill in fields based on the user's most recent similar request.
2+ Features
3+ - Detects previous requests for the same catalog item
4+ - Prompts user to reuse values from their last submission
5+ - Autofills fields like location, department, and justification
6+
7+ <img width =" 878 " height =" 395 " alt =" image " src =" https://github.com/user-attachments/assets/33ceabf5-2bbc-43e3-8792-f1f9a99699d2 " />
8+
9+
10+
You can’t perform that action at this time.
0 commit comments