Data Generator Application
Overview
The Data Generator application was created to quickly generate sample bulk data typically needed for
application or reporting testing. It can be used to generate any record and most field type values. The
objective was to provide a mechanism that would allow admins to define generator maps without any
scripting, but scripting is available if you need to take full control of the field value generation.
https://share.servicenow.com/app.do#/detail/bd0f7b9b2b0c2100bc401d2be8da150d
Application Components
The application consists of 4 modules within the Data Generator module. These are available to admin
users.
Generator Maps: defines which fields values are set for a given table
Generator Requests: defines how many records to generate from a map
Bundles: allows bulk processing of multiple generator requests
Logs: list of related log events
Data Generator Application Page 1
Data Generator Application
Creating a Map
Start by given the map a name and selecting a table where the records will be created.
By default, business rules will not be executed when records are inserted. This allows for faster record
creation. You can check the "Run business rules" option if you need rules to run.
When any record is created the system will automatically set the system fields (sys_created,
sys_created_by, sys_updated, sys_updated_by). In some cases, such as running a trend report based
on the created date, you may need to take control of setting these values, otherwise all records will
have a created date of whenever the generator ran. If you need to define these values, uncheck the
"Auto sys fields" option and define field maps for the system fields you need.
Click the Next button to continue.
Defining Field Maps
Click New from the Field Maps related list on the Generator form.
Data Generator Application Page 2
Data Generator Application
Field Map attributes
Field Map records have a quite a few options depending on the type of target field. Common attributes
are:
Map: automatically set from the parent Generator Map
Map table: automatically set from the parent Generator Map
Order: defines the order in which fields values are processed, order values are automatically
incremented but you can set as needed. Order is important when you need to leverage previously set
field vaues as explained in the DateTime or Script Generated sections.
Active: inactive field maps are not processed
Field: field on the Map table that we are defining a value for
Field type: automatically set from the Field value, this determines the options you have to control the
value generation
Script generated: for complex value generation, you can define your own script logic (see below)
Data Generator Application Page 3
Data Generator Application
Supported Field Types and Options
The following field types are supported with the listed options.
Type: Boolean
Processing: Randomly selects a true or false value
Options: optionally you can skew the likelyhood of a true value by setting an option of "likelihood:##'
where ## is a value between 0-100
Type: Reference
Processing: randomly selects a value from the referenced table
Source table: automatically set from the Field value
Source filter: define a condition to limit the list of records to select from
Type: String
Processing: string type fields need a String Data attribute to define what type of string value to
generate
String data: select one of the data types available, you will need to have an understanding of the target
field in order to select the best option
Options: options are based on the type of String data selected
• Word: Random word using Chance API. Valid options "syllables:#", "length:#".
• Sentence: Random sentence using Chance API. Valid option "words:#".
• Paragraph: Random paragraph using Chance API. Valid option "sentences:#".
• Email: Random email using Chance API. Valid option "domain".
• First name: Random first name using Chance API
• Last name: Random last name using Chance API
• Full name: Random full name using Chance API. Valid options "middle:true",
"middle_initial:true", "prefix:true".
• IP address: Random IPv4 address using Chance API
• Phone: Random 10 digit phone number using Chance API. Valid options "formatted:false".
• Latitude: Random latitude using Chance API. Valid options "min:#", "max:#".
• Longitude: Random longitude using Chance API. Valid options "min:#", "max:#".
• Integer string: Random integer string using Chance API. Valid options "min:#", "max:#".
• String: Random string using Chance API. Valid options "length:#", "pool:characterset".
• Pick one of...: Random selection from a list of comma seperated values specified in the 'Picks'
field.
Type: Number
Processing: Generated a random integer
Options: Define minimum and maximum range by setting min:#, max:# options.
Type: DateTime
Processing: randomly selects a date between one year ago and right now
Data Generator Application Page 4
Data Generator Application
Date begin field: set the begin range to a previously set target field (based on Field Map order), setting
this will override the value in Date begin
Date begin: specify a fixed range beginning
Date end field: set the end range to a previously set target field (based on Field Map order), setting this
will override the value in Date end
Date end: specify a fixed range end
Type: Choice
Processing: randomly picks from the valid choice valus on the field
Script generated values
When complex logic is needed, you can enable the Script generated values field. This will expose the
Script field.
Set variable answer to a valid value for the selected field.
Variable target is a GlideRecord representing the new record with all previously set (based on order)
field values.
You can leverage the chance variable which represents the Chance.js API which is available in the
Chance script include.
Duplicating a Map
You may want to have different maps defined for a single table, each with different fields or field
options. To make the creation of new maps quicker you can use the Duplicate Map related link on the
Generator Map form. This will create a new map with a copy of the current field maps.
Data Generator Application Page 5
Data Generator Application
Creating Generator Requests
Generator Requests need to be created before you can generate records based on the Generator
Maps. These can be created from the Generator Requests module or the related list on a Generaror
Map form.
Requests have the following fields:
Map: select a map that defines what the request will generator
Record count: how many records will be created
Status: read only field controlled by the system
Generating Records
To generator records, click the Generate Records related link on the Generator Request form or use
the list context menu from a list of Requests.
A progress worker will generate the records in a background process. The worker will automatically
refresh with the latest status.
Data Generator Application Page 6
Data Generator Application
Bundling Requests
Occationally you will need to generate data across multiple tables. This can be made easier by using
Bundles.
A bundle is a collection of Generator Requests that will be processed together. The order of generation
can be defined when you need to generate reference records first, then use them as reference values
on other tables.
Create a new Bundle from the Bundle module. Provide a name and description.
Add the Generator Requests you want to include in this bundle using the Requests related list on the
Generator Bundle form. Specify the order for each as needed.
In this example we defined the order to meet the following objective:
Create 100 CIs first since these CIs will be referenced later in the Change requests and Change
Affected Servers requests.
Create Change requests next since these will be referenced by the Change tasks which are created
next.
Finally create the Affected CI records referencing the previously created change requests and CIs.
Data Generator Application Page 7
Data Generator Application
Execute a Bundle
To execute a bundle and generate all of the Request records, click the Generate related link on the
Generator Bundle form.
Debugging
Most processing events are logged in the system log. You can access these through the Logs module.
Data Generator Application Page 8