how to access the input variables of a Reusable Test from a Run Server-Side Script step

JithinK
Tera Contributor

how to access the input variables of a Reusable Test from a Run Server-Side Script step within the same reusable test. I have tried with param and steps

gs.log(JSON.stringify(params)); // output: {}
gs.log(JSON.stringify(steps('/* sysid of input variable*/')) // getting below error

java.lang.IllegalArgumentException: Step id 23cb768dc335e61043d59e377d0131af is not valid
3 REPLIES 3

sunil maddheshi
Tera Guru

@JithinK Can you try with this
steps.getInputValue('my_input_variable_name');

 

Please mark correct/helpful if this helps you!

I have tired this, I hope 'my_input_variable_name' basically the column name of the input. But getting output undefined

JithinK_0-1748354675858.png

(function(outputs, steps, params, stepResult, assertEqual) {
    gs.log(steps.getInputValue('u_request_details'));

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

output
JithinK_1-1748354768626.png

 

Andy-L
Tera Contributor

Hi - I used the following approach to pass  Reusable Test input values to a script:

 

Instead of using the "Server Side Script" Step - I created a Custom Step configuration that can run a script. ( https://www.servicenow.com/docs/bundle/yokohama-application-development/page/administer/auto-test-fr... )

 

 

So first, 

  • I created a new Step Config (Script / Server) . 
  • I added script, input & output variables specific for the use case.
  • Then, when creating the test, I add a new test step based on the Step Config and pass the reusable inputs to the Script Step via a pill.

 

It is also possible the create a generic Step Config with a script input parameter that allows the script to be defined within the Test Step itself - by using a script input parameter  (similar to the current Run Server Side Script step). Then the Step Config Script will call JavaScript 'eval' on the parameter.  However, I think this approach should be avoided, and all of the script logic kept inside the Step Config. Then just create a dedicated Step Config for each use case.