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

lucascd
Giga Contributor

Hi guys.

I managed to get a bit better, by having the Device sys_ID showing up in the Output message by using first_record instead of record_id. But still getting undefined for the CI.

Here is my updated code:

 

(function(outputs, steps, stepResult, assertEqual) {
	

	
	var sysIDstep1 = 'fa66c5b0dbd773006d50f9baae961987'; //Step 1 Sys ID
	var recordIDStep1 = steps(sysIDstep1).first_record;
	var cmdbNumero = recordIDStep1.cmdb_ci;
	var record_id;
	
	
	outputs.table = 'cmdb_ci_linux_server';
	outputs.record_id = cmdbNumero;

	
	gs.log('body ' + record_id);
	gs.log('body type' + (typeof record_id));
		
	
	if (outputs.record_id) {
		stepResult.setOutputMessage("sysIDstep1: "+ sysIDstep1 + "  recordIDStep1: "+ recordIDStep1 + "    cmdbnumero "+ cmdbNumero + "recordID" + record_id);
			
		return true;
	} else {
		stepResult.setOutputMessage("Failed Step");
		return false;
	}
	
})(outputs, steps, stepResult, assertEqual);

 

 

Masha
Kilo Guru

Try replacing record_id with outputs.record_id in your stepOutputMessage.

 

lucascd
Giga Contributor

Hi Masha.

I tried that but still showed "undefined" in the results.

lucascd
Giga Contributor

Hi guys.
I'm still struggling with this, after attempting a few more changes.

Any ideas on how to solve this "undefined" issue?

 

I've been working with ATF for a while and it's very useful to me, but now I need to use the scripting steps to develop more advanced test cases and I can't pass this basic part of input/output. 

 

Any help would be appreciated 🙂

Thank you.