Returning a value from User Code into a recorder variable

Class library usage, coding and language questions.
tgagel
Posts: 33
Joined: Tue Jun 04, 2013 7:50 pm

Returning a value from User Code into a recorder variable

Post by tgagel » Wed Jul 15, 2015 6:11 pm

A developer has created a small C# user code snippet to allow those building tests to parse some formatted text passed into the user code method and pull out certain pieces for later use. I intended to store the returned data in a recorder variable (similar to using the 'Get Value' action to populate a variable) but can't find a way to do that.

When calling user code from Ranorex Recorder Script, is there a way to capture the returned value from the user code? As you can see in the screenshot, I am able to specify the 2 parameters for the user code method but I don't see any Ranorex options for grabbing the output. Ideally I am looking for something that combines the User Code and Get Value (storing something in a variable) Actions.

More info on the user code:
A single static method to the CodeLibrary class, GetTextFromJson(string json, string propertyName).

The first parameter is the full Json string read off the page. (e.g. {"Organization":"OrgID1","Abbreviation":"35225","BatNumber":"2272","ComNumber":"03986"})

The second is the name of the field you'd like the text from, for example "Organization".

The resulting value (e.g. "OrgID1") is returned by the method.
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Returning a value from User Code into a recorder variable

Post by odklizec » Thu Jul 16, 2015 8:02 am

Hi,

If you want to use the return value from UserCode within the same recording module, then all you need to do is to create a new recording module variable (e.g. returnVal) and then assign this variable with return value from user code. This must be done within the UserCode itself...
ReturnValue.png
If you want to share the UserCode result amongst multiple modules, learn here how to do this properly:
http://www.ranorex.com/blog/sharing-dat ... to-another
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Returning a value from User Code into a recorder variable

Post by Support Team » Thu Jul 16, 2015 1:43 pm

Hi odklizec,
Thank you for your answer we really appreciate your work in this forum, but I have to correct you in this regarding.

You can bind the return value of a user code module direct to a module variable by opening the properties tab of your code action as shown here
ReturnValueUserCode.png
Please also find attached a short sample solution.
ReturnValue.zip
Regards,
Markus (S)
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Returning a value from User Code into a recorder variable

Post by odklizec » Thu Jul 16, 2015 2:04 pm

Hi Markus,

Cool! One learns something new every day ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

tgagel
Posts: 33
Joined: Tue Jun 04, 2013 7:50 pm

Re: Returning a value from User Code into a recorder variable

Post by tgagel » Thu Jul 16, 2015 2:24 pm

Thanks. That's exactly what I needed!