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 directly to the generated record. Oftentimes it is more desirable to redirect users back to the catalog or their homepage and provide them with an information message telling them that their record has been created. Here’s a script that allows you to do that.



The following 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 message will be displayed at the top of the page that the user gets redirected to. To use this script, simply paste it into the ‘Script’ field on any record producer in your Service-now instance.

  • You can add 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 want to access (current.short_description, current.number, etc.).
  • You can add the value of any record producer variable to the message by accessing the ‘producer’ object followed by the name of the variable you want 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" >' + current.number + '</a>';
var message = 'Change ' + link + ' has been created.<br/>';
message += 'Thank you for your submission.';

//Add the information message
gs.addInfoMessage(message);

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

Here’s another example that shows how you can access record 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. It performs a similar operation 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 = "Please contact customer with new password via: " + producer.contact_me;
notes += '\nCaller : ' + producer.caller_id.getDisplayValue();
notes += '\nSystem : ' + 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 password for ' + producer.caller_id.getDisplayValue() + ' on ' + producer.cmdb_ci.getDisplayValue();

//Populate reference fields
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 message
var message = 'An incident ' + current.number + ' has been opened for you.<br/>';
message += 'The IT department will contact you for further information if necessary.<br/>';
//Add the information message
gs.addInfoMessage(message);
//Redirect the user to the 'ess' homepage
producer.redirect = 'home.do?sysparm_view=ess';