Create Global variables on fly

Hi , I am fairly new to Katalon studio and I am trying to create a runtime username and add it to the request body. Here are the steps which I have tried doing.

  • Created a Global variable
  • Created a custom method to generate random email id

When I print out the request body I see that the email is not being set to the variable. Any help would be appreciated on this.!


	void addGlobalVariable(String name, def value) {
		GroovyShell shell1 = new GroovyShell()
		MetaClass mc = shell1.evaluate("internal.GlobalVariable").metaClass
		String getterName = "get" + name.capitalize()
		mc.'static'."$getterName" = { -> return value }
		mc.'static'."$name" = value

Thank you so much! Could you also advise me , how to reset the Global variable value at runtime.