Binding repository variable to data in code module

Ask general questions here.
hsarmah2021
Posts: 16
Joined: Tue Oct 27, 2020 1:43 pm

Binding repository variable to data in code module

Post by hsarmah2021 » Thu Apr 15, 2021 11:50 am

Hi everyone,
Does anyone has experience of binding a repository variable in a code module? I have a repository variable for one repo object, when I use this object in my code module I don't see the variable created for this module automatically. But when I use the same object in a recording module, the variable is automatically created and I can bind it. I know I can create variable in a code module by right clicking, but then how does this variable link to the repository variable?

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

Re: Binding repository variable to data in code module

Post by odklizec » Thu Apr 15, 2021 1:27 pm

Hi,

What you need to do is to instantiate repository in code module. And then you can easily access repo variable in code module and change its content. To use data binding, simply create a code module variable, which you can bind to data source. And then you can use both module variable and repo variable like this...
repoVariable.png
repoVariable.png (25.37 KiB) Viewed 128 times
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
Stub
Posts: 439
Joined: Fri Jul 15, 2016 1:35 pm

Re: Binding repository variable to data in code module

Post by Stub » Thu Apr 15, 2021 1:29 pm

You have to manually assign the module parameter to the repository in your code module. Something like this, where the repo item SomeDialog.SomeNamedItem has an RxPath that includes the $SomeNamedItem variable.

Code: Select all

repo.MyApp.SomeNamedItem = MyModuleParameter;
repo.MyApp.SomeDialog.SomeNamedItem.Click();
I do this all the time as I use Code Modules exclusively over Recordings.

:

And Pavel's answer is of course superior because pictures!

hsarmah2021
Posts: 16
Joined: Tue Oct 27, 2020 1:43 pm

Re: Binding repository variable to data in code module

Post by hsarmah2021 » Fri Apr 16, 2021 2:49 pm

Thank you both for replying, let me try this.