ATF: steps(SYS_ID) evaluates to undefined when run in server side script

SNAdmin47
Kilo Sage

I'm running a test where I have a random string generated in the first test step and I then want to use the random string value in a later server side script.

 

  • The sys_id of that first step with the random string is 'febec708ebf6c210d2e4ff47bad0cd5b'.
  • I've created a variable capturing the step using 'steps' and the sys_id of the first test step, and then I've added random_string to the variable (as per ServiceNow's ATF Product Doc).
  • I then want to use this variable 'randomString' in a server side script query to confirm if there's a sys_journal_field which contains this randomly generated string as a value. 
(function(outputs, steps, params, stepResult, assertEqual) {
        var randomString = steps(febec708ebf6c210d2e4ff47bad0cd5b).random_string;
		var worknotes = new GlideRecord('sys_journal_field');
        worknotes.addQuery('value', "CONTAINS", randomString);
        worknotes.addQuery('element', 'work_notes');
        worknotes.query();
        var worknotesNumber = worknotes.getRowCount();
        if (worknotesNumber != 2) {
            return false;
        }
		if (worknotesNumber === 2) {
            return true;
        }
    }
)(outputs, steps, params, stepResult, assertEqual);

However, I'm consistently getting the following error:

SNAdmin47_0-1718807367930.png

'Test failed due to JavaScript error executing step:
ReferenceError: "febec708ebf6c210d2e4ff47bad0cd5b" is not defined.'

 

Anybody able to tell me what I'm doing wrong here?

 

1 ACCEPTED SOLUTION

Zach Koch
Giga Sage

Does your line of code here

 

var randomString = steps(febec708ebf6c210d2e4ff47bad0cd5b).random_string;

 

need to be?

 

var randomString = steps("febec708ebf6c210d2e4ff47bad0cd5b").random_string;

 

Your error is telling you that your febec708ebf6c210d2e4ff47bad0cd5b value isn't defined, since you have it written like it's a variable.

View solution in original post

3 REPLIES 3

Zach Koch
Giga Sage

Does your line of code here

 

var randomString = steps(febec708ebf6c210d2e4ff47bad0cd5b).random_string;

 

need to be?

 

var randomString = steps("febec708ebf6c210d2e4ff47bad0cd5b").random_string;

 

Your error is telling you that your febec708ebf6c210d2e4ff47bad0cd5b value isn't defined, since you have it written like it's a variable.

Goshdangit, that might have done it! I'm slightly kicking myself for not having tried that.... Thanks @Zach Koch , I'll just test a bit more to confirm it's right and then if so I'll be back to mark as accepted solution. 🙂 

Great! Glad that helped!