Forum Discussion
ChrisAdams
4 years agoSuper Contributor
You need a couple of steps to achieve this. Firstly, a Groovy Script to load the file and secondly, the service call itself.
The Groovy script step must come before the service call. Here's an example, let's call the step "Get Payload - Groovy Script"...
import java.io.File;
// Basic code to reference the file.
def fullFolderPath = "C:\some folder\sub folder\";
def fileName = "payload.txt"
def fullFilePath = fullFolderPath + fileName;
// This var will contain the contents of the file.
String returnValue;
log.info("Opening Payload file ${fileName}.");
try {
returnValue = new File(fullFilePath).text;
} catch(FileNotFoundException e){
log.info(e);
}catch(IOException e){
log.info(e);
}
return returnValue;
Then, in the payload section of the request, you can 'call and pull in the result' of the Groovy script by entering...
${Get Payload - Groovy Script#result}
Here's a screenshot to reinforce...
chaitanya509
4 years agoOccasional Contributor
Thanks Chris ! I am able to get the data from the file , Can you please let me know how can i call this groovy script from my SOAP Request payload. when i am trying to access the script from SOAP request xml window like ${NameofStep#Result} i am getting "Invalid request" error