R

ecord producers in Service-now allow users to create records on any table directly from the Service catalog interface. Typically, record producers are used to allow users to create incident or change request records. When the record is submitted using a record producer, you are redirected straight to the generated tape. Oftentimes it is more than desirable to redirect users back to the catalog or their homepage and provide them with an information bulletin telling them that their record has been created. Here'south a script that allows yous to do that.



The post-obit script can be used to redirect a user to a page other than the record created by the record producer. It also adds an information message containing a link to the record generated. The information bulletin volition be displayed at the top of the folio that the user gets redirected to. To utilise this script, simply paste it into the 'Script' field on whatever record producer in your Service-at present instance.
  • You lot tin can add together the value of anything from the generated record to the message by accessing the 'current' record object followed by the name of the field you lot want to admission (current.short_description, current.number, etc.).
  • You lot can add the value of any record producer variable to the message past accessing the 'producer' object followed past the name of the variable you lot desire to access (producer.var1, producer.var2, etc).
//Create the html contents of the information message
var link = '<a href="change_request.do?sys_id=' + current.sys_id + '" class="breadcrumb" >' + electric current.number + '</a>' ;
var bulletin = 'Change ' + link + ' has been created.<br/>' ;
message += 'Thanks for your submission.' ;

//Add together the data bulletin
gs.addInfoMessage (bulletin) ;

//Redirect the user to the homepage
producer.redirect = 'home.do' ;

Here'south another case that shows how you tin access tape producer variables using the 'producer' object. This script takes the values of the 'caller_id', 'cmdb_ci', and 'contact_me' variables, and combines them to be populated into the 'work_notes' field on the generated record. Information technology performs a similar functioning to populate the 'short_description' field.

//Get the values of record producer variables to populate the 'work_notes' and 'short_description' on generated record
var notes = "Delight contact customer with new password via: " + producer.contact_me ;
notes += '\northCaller : ' + producer.caller_id.getDisplayValue ( ) ;
notes += '\northwardOrganisation : ' + producer.cmdb_ci.getDisplayValue ( ) ;
notes += '\nContact : ' + producer.contact_me ;
//Populate the 'work_notes' field
current.work_notes = notes;
//Populate the 'short_description' field
current.short_description = 'Reset the countersign for ' + producer.caller_id.getDisplayValue ( ) + ' on ' + producer.cmdb_ci.getDisplayValue ( ) ;

//Populate reference fields
electric current.caller_id = gs.getUserID ( ) ; //Populate Caller with current user
current.assignment_group.setDisplayValue ( 'Hardware' ) ; //Populate Assignment Group (name must be unique)

//Create an information bulletin
var message = 'An incident ' + current.number + ' has been opened for you lot.<br/>' ;
message += 'The IT department will contact you for farther information if necessary.<br/>' ;
//Add the information message
gs.addInfoMessage (message) ;
//Redirect the user to the 'ess' homepage
producer.redirect = 'domicile.practice?sysparm_view=ess' ;