Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Automated Test Framework - How to solve "undefined" as output of a ATF test step (Run server side script).

lucascd
Giga Contributor

Hello team,

 

I'm currently working on a test case in Automated Test Framework in the Discovery area.

I have a "Record Query" test step that returns a specific record from the discovery_device_history table. In the following step I execute some validations in the fields successfully.

In the following step, I have a Run Server Side Script test step that I want to get the CMDB CI value of the discovery_device_history record and use it as an Output - so in the next steps I can open and validate the CI record.

 

Here is my script:

(function(outputs, steps, stepResult, assertEqual) {
    
	var sysIDstep1 = 'fakkeekkeekk773006d50f9baae961987'; //Step 1 Sys ID
	var recordIDStep1 = steps(sysIDstep1).record_id;  
	
	var record_id;
	outputs.table = 'cmdb_ci_linux_server';
	outputs.record_id = recordIDStep1.cmdb_ci; 


	stepResult.setOutputMessage("Output: "+ sysIDstep1 + recordIDStep1 + record_id);


	
	
})(outputs, steps, stepResult, assertEqual);

 

My output:

Output: fakkeekkeekk773006d50f9baae961987undefinedundefined

 

 

Any suggestion of what I am doing wrong and how I can fix the script? So the CI becomes my output?

 

Thank you in advance.

1 ACCEPTED SOLUTION

Hi Elijah

Sorry for the late response. Yes, I figured a way to do it! 🙂

 

(function(outputs, steps, stepResult, assertEqual) {
 
	// Returns the server sys_id, using Step that has Device History as output
	var recordIDStep10 = steps('SYS ID OF THE STEP').first_record;
	
	// Gets the zOS server data/record
	var queryString = "sys_id=" + recordIDStep10;
        var request = new GlideRecord('discovery_device_history');
        request.addEncodedQuery(queryString);
        request.query();
	var theIDIwant = '';
	
    if (request.next()) {
       theIDIwant =  request.cmdb_ci;
	
		
    } else {
		// Doesn't exists a server - Failure
	}
	
	var record_id;
	outputs.record_id = theIDIwant;
	
	stepResult.setOutputMessage("SYSID: " + recordIDStep10 + " SYS ID of CI: " + theIDIwant);

})(outputs, steps, stepResult, assertEqual);


View solution in original post

6 REPLIES 6

I'm having the same problem, did you figure out any solutions?

Hi Elijah

Sorry for the late response. Yes, I figured a way to do it! 🙂

 

(function(outputs, steps, stepResult, assertEqual) {
 
	// Returns the server sys_id, using Step that has Device History as output
	var recordIDStep10 = steps('SYS ID OF THE STEP').first_record;
	
	// Gets the zOS server data/record
	var queryString = "sys_id=" + recordIDStep10;
        var request = new GlideRecord('discovery_device_history');
        request.addEncodedQuery(queryString);
        request.query();
	var theIDIwant = '';
	
    if (request.next()) {
       theIDIwant =  request.cmdb_ci;
	
		
    } else {
		// Doesn't exists a server - Failure
	}
	
	var record_id;
	outputs.record_id = theIDIwant;
	
	stepResult.setOutputMessage("SYSID: " + recordIDStep10 + " SYS ID of CI: " + theIDIwant);

})(outputs, steps, stepResult, assertEqual);