Can I select random value from the selected table in Automation Test Framework step ?

Bharat
Kilo Explorer

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 ?

5 REPLIES 5

Mark Stanger
Giga Sage

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...

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?

I keep receiving the failure message below for my next step:

 

I'd like to configure a test step such as "Query Random Record".

Would I simply copy this into "Step Execution Script" section.