Automate Schedule has a built-in command feature (the Web Service Request command) that allows you to call an external web service from an Automate Schedule job. When you create a job with a web service request command in it, you can set it up so the response data, which is usually in XML or JSON format, is sent to a local file. That's useful, but there may be times when you'll need to pass values from the response directly into subsequent commands or web service requests. You can accomplish this by using the extractvariable.bat utility.


Extracting Values from a Response

The extractvariable.bat utility is a command line API that can be used after a web service call. It pulls a value from the response data file of a web service request. It then uses that value to create an environment variable that can be used in a subsequent web service request in the Automate Schedule job.

When adding the command to run extractvariable.bat to the job, several command parameters are required:

  • {file} - The file to scan for the text between markers (typically the response output file from a prior web service request).
  • {begin_marker} - The beginning text marker for the data to extract.
  • {end_marker} - The ending text marker for the data to extract. An empty string value means End-Of-Line.
  • {return_string} - Output command string that receives the text value identified by the {begin_marker} and {end_marker} and sets an environment variable for the value. The command string you provide must contain a question mark (?) that will be replaced by the value extracted from the response data.
  • {output_bat} - The output .bat file is created with the updated {return_string} command inserted as the content of the file.

Windows command syntax:

"{agent_path}\extractvariable.bat" {file} {begin_marker} {end_marker} {return_string} {output_bat}

Note: The {agent_path} is typically "C:\Program Files (x86)\Help Systems\Automate Schedule Agent" on a default Windows installation.

Alternate command syntax (works with UNIX, Linux, and Windows):

This alternate command performs the same function of extracting a value and inserting it into a command string. However, the output text will be sent to the console rather than to a file. You can redirect the output into an executable script on your own.

java -cp {classpath} com.helpsystems.enterprise.core.util.ExtractVariable {file} {begin_marker} {end_marker} {return_string}

Note: The {classpath} is "{agent_path}/lib/schent-mp-module.jar". The {agent_path} is typically "/opt/automate-schedule/agent" on a default install on a UNIX/Linux system.



Given this XML output in the file %WS_OUTPUT_FILE% from a web service request command run from an Automate Schedule job:

<!--?xml version="1.0" encoding="UTF-8"?-->
<content>Job 'WS-DEMO' submitted. Run number is '1117'</content>

The following commands, added to a job, run the web service command that gives the above response, and extracts the run number from the above response into a variable named WS_ASJOB_RUN_ID that could then be used in a subsequent web service request command in the job:

Showing a sample of commands that would pass a value into a web service call.

The first command sets an environment variable for the response output file.

set WS_OUTPUT_FILE=ws_output.xml

Then, the web service request command is run. When setting up the command in the job, be sure the output file name is the same as what you used above.

{...web service command with output going to %WS_OUTPUT_FILE%...}

This sets an environment variable for an empty .bat file that's created.

set SET_JOBID_BAT=set_jobid.bat

This extracts the value from the output file to a variable in the empty .bat file that was created above. The {file} parameter indicates which output file is scanned. The program scans for the first file line with text between the {begin marker} and the {end marker}. The first matching text found is substituted for the question mark (?) in the output command string (the {return_string}) and is sent to the {output_bat} file.

"C:\Program Files (x86)\Help Systems\Automate Schedule Agent\extractvariable.bat" "%WS_OUTPUT_FILE%" "<run_number>" "<" "set WS_ASJOB_RUN_ID=?" "%SET_JOBID_BAT%"

This runs the .bat file that creates the variable for the value extracted from the output file.

Note: It's important that this file is called immediately after the above command.


This prints the value to the console.

echo Automate Schedule Job #%WS_ASJOB_RUN_ID%

The environment variable (WS_ASJOB_RUN_ID) that was just created can be used in a subsequent web service request command by adding it to the Runtime Environment Variables section.

Showing how to use the extracted value as an environment variable.


Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: October 24, 2019