Can I select random value from the selected table in Automation Test Framework step ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 06:11 AM
For Example In my test step I have opened the Incident table now in Automation test framework I have to select the particular one record which I have to open but Can I select random record from the available list of incident or specific one ?
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 02:35 PM
You can do this by running a server-side script step to query for the record you want and return an ID (which can be selected in the subsequent 'Open an Existing Record' step. Here's a couple of screenshots showing how to do this...
1) 'Run Server Side Script' step script. This example queries for a random, active Incident record. The key here is to set 'outputs.record_id' with the sys_id of the record you want to use.
(function(outputs, steps, stepResult, assertEqual) {
// Query for a random incident record
var rec = new GlideRecord('incident');
rec.addQuery('active', true); // Adjust query parameters here
rec.query();
if(rec.hasNext()){
//Get the number of records queried
var numRecs = rec.getRowCount();
//Get a random number
var randomNumber = Math.floor(Math.random()*numRecs);
//Set the row number to 'randomNumber'
rec.setLocation(randomNumber);
outputs.record_id = rec.sys_id;
}
})(outputs, steps, stepResult, assertEqual);
2) In your 'Open an Existing Record' step you can then select the record ID output from step 1 as shown here...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2019 12:13 PM
I've tried running this script for a scoped test step but it keeps failing. I only replaced "incident" with the current table name.
Thought?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2019 12:33 PM
I keep receiving the failure message below for my next step:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2019 02:45 PM
I'd like to configure a test step such as "Query Random Record".
Would I simply copy this into "Step Execution Script" section.