Unable to use Global variable


i want to use different profiles to run our test suites. In these variables i use a global variable (“baseUrlSubDomain”). i want to use this variable for a distinction in my API groovy.
So, if baseUrlSubdomain is “xyz” then use api_token_xyz else use api_token_zxy.
Code is:

But when i start my test suite, i get this error message:

Can anyone help me to solve this problem?

have you import related package?

These are all packages imported:

don’t access them using “this.”
you are tring to access them as if they were variables in your class which they are not

access them like this

this will help you

When i access them with GlobalVariable.baseUrlSubdomain i get this error message:

@Strohfus.Marvin Either you have a spelling mistake on the GV variable, or you have not declared the GV variable in the GV table or you need to add internal in front of your GV variable. Groovy is case-sensitive–a capital letter is not the same as a lower-case letter.

If the GV is properly spelled and is in the GV table, then restart KS. Also, you can change the import statement as below and then you should not need to add internal in front:

import internal.GlobalVariable as GlobalVariable

@grylion54 I have restarted Katalon and it does not work at all. I copied the variable name from the profile and pasted it in the groovy, so it can not be a spelling mistake.
The variable is also declared in the profile as you can see here:

Any other ideas?

Just the last one I had above. When you hover your mouse over the GV phrase, do you get a pop-up about internal.GlobalVariable?

@grylion54 when you mean this, i get the pop-up.

i looked at the second error its not the same as the first one , your issue is now with the response variable

Yes, the error was with the response object. This object did not “survive” the if-loop, i wanted to use the response object out of the loop, but i have to do this also in the if-loop. Now it works and the disctinction is ok.

the code you wrote is in a custom keyword, or just test script?
from the error you get, looks like is a custom keyword (api.SalesCloudAccount), which basically is a class.
so you have to define the variable before to use it (use a def response somewhere in your code, before the if chain)