Identify which ServiceNow Record Producer was used to create a record

https://www.servicenowguru.com/reporting/identify-servicenow-record-producer-create-record/


ecord producers are a great piece of ServiceNow functionality that allows for the creation of records in any tablevia the standard Service Catalog interface. This capability has been around for quite a while and odds are that you’re already using it in your system to allow end-users to create new incidents…among other things.

Over the years I’ve worked with ServiceNow, I’ve seen several requests to be able to report on or identify the record producer used to create a particular record. This would allow for easier identification of the entry point for record producer transactions. Unfortunately, ServiceNow doesn’t give us a simple way of accomplishing this. Even though there is a record producer ‘Script’ field and a ‘producer’ script object to work with, nothing is built to be able to dynamically identify the record producer used. This means that you’re stuck hard-coding values in a script or adding unnecessary variables to your record producer forms for every single record producer in your system. Read on for a fairly simple solution to this problem!

Record Producer Populated

This configuration can be accomplished in a few simple steps as shown below…

  1. Create a new field to store the value of the record producer used.

    We’ll want to store the record producer value on each target record that is created. As such, you’ll need a field to store that value in. I think the best solution is simply to create a new reference field referencing the ‘Record producer’ [sc_cat_item_producer] table named ‘Record producer’ [u_record_producer] on the ‘task’ table. That way, you can have one shared field that will be available to almost everything that you’ll usually use with record producers. If you’ve got additional tables that don’t extend ‘task’, just repeat the same step there as well.

  2. Create a new business rule on the ‘Record Producer [sc_cat_item_producer]’ table.

    The purpose of the business rule is to overcome the issue this article is about. We do this by leveraging the record producer ‘Script’ field to populate the ‘Record producer’ [u_record_producer] field created in the previous step. The business rule simply populates the record producer sys_id value into the record producer ‘Script’ field every time the record producer is inserted or updated and then the standard record producer script/creation process takes over and writes the producer Sys ID to the field per normal operations. If you need this to work for non-task tables, you can simply create a duplicate business rule there.

‘Force population of record producer used’ Business rule
Name:

 Force population of record producer used


Table:

 Record producer [sc_cat_item_producer]


When:

 Before


Insert:

 True


Update:

 True


Advanced:

 True


Order:

 1100


Condition:

 current.script.indexOf(‘Force population of record producer’) == -1


Script: /***There is no dynamic way to record the record producer used so we can force it here
by modifying the script field entry on the record producer.  Record producer will be 
populated in a reference field on the target record named 'u_record_producer' (which 
will need to be created).***/



current.
script 
= current.
script 
+ 
'\n\n\n' 
+ 
'/***DO NOT REMOVE OR MODIFY THIS SECTION!!! Automatically added by "Force population of record producer used" business rule. \nForces population of this record producer sys_id into the target record for reporting purposes.***/\n' 
+ 
'current.u_record_producer = ' 
+ 
'"' 
+ current.
sys_id 
+ 
'";';

Please note that you will need to manually update every record producer in the system that you want this to work with in order for the producer script to be updated as necessary!

If you’ve done all of the above steps correctly, you should end up with a nicely-populated ‘Record producer’ reference field on each generated record. This value can then be used for reporting or other purposes in your system!

Record Producer Populated