How to use Global Variables on XML Request Body?

How to use Global Variables on XML Request Body?

Hi all,

I’m new to Katalon Studio and i’m trying to understand the use of variables and in particular Global Variables.

I’ve imported a SOAP Web Service into Object Repository.
After that I’ve created a profile a defined some global variables on the image below and set the new profile as default.

I also have chosen the created profile.
Active profile

On the web service WSDL field and Service Endpoint, I replaced the hostname with ${GlobalVariable.endpoint}.
The variable works and the request is sent to the correct endpoint.

On then request local variables, I’ve created “local_app” variable and defined it as Global Variable with value GlobalVariable.app.

On the request message, on the XML itself I included the 2 variables:

  • ${GlobalVariable.app} and
  • ${local_app} that points to ${GlobalVariable.app}

In the response I can see Application_Test which is the correct string value for the ${local_app} variable, but for the ${GlobalVariable.app} I get the string ${GlobalVariable.app} instead of Application_Test.

I’ve read a lot of posts and on one of them the issue was about some incorrect syntax, but the correct syntax was not included.

I’m assuming that it is still possible to use Global Variables on a Request XML Message Body.
If this option is still available? Can you help on what am I doing wrong?

The version I have installed is 10.2.0.

Thanks.

1 Like

Perhaps, no.

I read the Groovy source code of com.kms.katalon.core.testobject.RequestObject and others, I found the string ${GlobalVariable.app} in the XML Request body will never be interpolated with the value you gave in the Execution Profile.

(I don’t know how the Katalon’s official documentation writes about “Global Variables on XML Request Body”. When I want to find out a truth about how Katalon works, I always read the source and do some experiments.)

However, you, @dalia.piedade, already know how to pass the value of Global Variables into XML Request body, don’t you?

In the sample case above, you introduced a variable local_app as a parameter to RequestObject. Via this, you could pass the value of GlobalVariable.app into a place-holder ${local_app} in XML. And, that worked. This proves that you could achieve what you wanted. Good enough, isn’t it?

The issue arises because Global Variables in XML request bodies require explicit parameterization in Katalon Studio. Here’s how to fix it:


1. Define Request Parameters Properly

Don’t use ${GlobalVariable.app} directly in XML. Instead:

  1. In your Request Object:
  • Go to the Variables tab.
  • Add a parameter named app and map it to GlobalVariable.app.

2. Use Parameter Syntax in XML

In the XML body, reference the parameter with ${variableName}:

xml

<Application>${app}</Application>

This tells Katalon to replace ${app} with the value from the mapped Global Variable.


3. Avoid Direct Global Variable References

Why It Fails: Katalon doesn’t resolve ${GlobalVariable.app} in raw XML. Use parameters instead.


4. Step-by-Step Example

a. Request Object Configuration:

  • Variables Tab:
Parameter Value
app GlobalVariable.app
  • Request Body:

xml

<Body>
  <Application>${app}</Application>
</Body>

b. Execution Workflow:

groovy

// Set Global Variable
GlobalVariable.app = "Application_Test"

// Send SOAP request
WS.sendRequest(findTestObject('YourSOAPRequest'))

5. Verify Parameterization

Check the Request Logs in the Log Viewer to confirm substitution:

Request Body Sent:
<Body>
  <Application>Application_Test</Application>
</Body>

Alternative: Script-Built XML

For dynamic content, construct the XML programmatically:

groovy

String xmlBody = """
<Body>
  <Application>${GlobalVariable.app}</Application>
</Body>
"""

// Use WS.sendRequestWithBody
def response = WS.sendRequestAndVerify(
  WS.convertStringToXml(xmlBody),
  [url: GlobalVariable.endpoint]
)

Why Your Local Variable Worked

When you defined local_app as a request parameter mapped to GlobalVariable.app, Katalon replaced ${local_app} because it’s recognized as a parameter. Direct Global Variable references in raw XML aren’t parsed automatically.


Summary

  • Use Parameters: Map Global Variables to request parameters via the Variables tab.
  • Avoid Inline Globals: ${GlobalVariable.app} won’t resolve in raw XML bodies.
  • Script for Complexity: Build XML dynamically for full control.
1 Like