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).
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
//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.
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
//Redirect the user to the 'ess' homepage
producer.redirect = 'home.do?sysparm_view=ess';
I tried this redirect on our CMS page but it takes me to the home page within the iFrame… the header is included in the iFrame. How can I get it to redirect back to the homepage outside of the iFrame?
producer.redirect = ‘home.do?sysparm_view=ess’;
Anyone know how force a record producer to update an existing record instead of inserting a new one? Is there an abort command you can put in the record producer script?
I’ve seen this done before. What you would need to do is use ‘current.setAbortAction(“true”)’ in your producer to abort the producer insert. Then your update would need to be a GlideRecord query and update.
I have tried the script. Its working fine in IE & Google Chrome,but not in Mozilla Firefox. Why is it so?
I’ve never had an issue with this in Firefox so I’m not sure why it wouldn’t be working for you. If you can set it up and reproduce it in the ServiceNow demo instance I can take a look.
I found out that Info message doesn’t appear in chrome which is a known issue and will not be resolved.
Another thing is that current.number doesn’t contain anything. I am unable to get the reference of created record in current object. So the message that is added in Firefox is like this-
“An incident has been opened for you.
The IT department will contact you for further information if necessary.”
An IFrame with buster set to true will continue to expand the Firefox scroll bar (FF v49.01). If not, the the info message appears but the record producer shown is erroneous.
Regarding the current.number value, it will not work if “Assign a task number only upon insert (prevents unused numbers).” property is enabled.