- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 07:30 AM
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:
'Test failed due to JavaScript error executing step:
ReferenceError: "febec708ebf6c210d2e4ff47bad0cd5b" is not defined.'
Anybody able to tell me what I'm doing wrong here?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 07:36 AM - edited 06-19-2024 07:36 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 07:36 AM - edited 06-19-2024 07:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 07:52 AM
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. 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 08:29 AM
Great! Glad that helped!