Create/update variable within test

Is there any way to create a variable with the text of an element from within a test case. Kind of like Selenium IDEs “store” function.

At the moment I am trying “testvariable = WebUI.getText(findTestObject(‘TargetElement’))” and I have also tried " def testvariable = WebUI.getText(findTestObject(‘TargetElement’))"

When I looked at a variable

I figured it out:
“testvariable = WebUI.getText(findTestObject(‘TargetElement’))” wont work
but if you do “testvariable = WebUI.getAttribute(findTestObject(‘TargetElement’),‘value’)” then it should.