Page 1 of 1

Dynamically resetting repository items

Posted: Fri Jul 12, 2013 3:06 pm
by KurtZ
Background:
I have a multi-tab form used for performing searches. Each tab contains basically the same objects, with the only difference being the tab's index. I am creating rooted folders in my repository. Rather than create 5 folders containing the same 20 objects (100 total objects), I want to create 1 folder with 20 objects and set/reset the folder based on which tab I need to use.

Issue one:
When resetting the repository path of my rooted folder, my change is being appended to the current path as opposed to updating it.
string PathOriginal = RepoPath.VariableTab.SelfInfo.AbsolutePath.ToString();
//Reset Path
RepoPath.VariableTab.SelfInfo.Path = "container["+i+"]";
string PathUpdated = RepoPath.VariableTab.SelfInfo.AbsolutePath.ToString();

//I am getting
PathOriginal = "form/element/container"
PathUpdated = "form/element/container/container[2]"

//I am expecting
PathUpdated = "form/element/container[2]"
Issue two:
The update is not being applied to items nested inside the folder.
string ChildPathOriginal = RepoPath.VariableTab.textbox_IDInfo.AbsolutePath.ToString();
//Reset parent folder's path
RepoPath.VariableTab.SelfInfo.Path = "container["+i+"]";
string ChildPathUpdated = RepoPath.VariableTab.textbox_IDInfo.AbsolutePath.ToString();

//I am getting
ChildPathOriginal = "form/element/container/.//text[@name='id']"
ChildPathUpdated = "form/element/container/.//text[@name='id']"

//I am expecting
ChildPathUpdated = "form/element/container[2]/.//text[@name='id']"
Thanks

Re: Dynamically resetting repository items

Posted: Tue Jul 16, 2013 9:47 pm
by Support Team
Hello,

Thank you for providing your code snippet.
I think it would be easier to use repository variables instead of changing the absolute path of your repository element?
Please read the "Using Variables within the Repository" section in order to get more information how to create and use repository variables.
Thank you!

Regards,
Bernhard

Re: Dynamically resetting repository items

Posted: Wed Jul 17, 2013 12:32 pm
by KurtZ
Thanks Bernhard.

Unless I'm missing something, the problem with making the repo path variable as you have suggested means I have to maintain yet another column of data in my data sheet. This isn't a huge sticking point, but it requires additional manual interaction instead of having a snippet of code that does the work for me.

I could also use variations of Find to create my objects at runtime, but that defeats the purpose of having a repository.

It seems like resetting the repo item's path through code could work, it's just not working correctly.

Any other suggestions?
Thanks

Re: Dynamically resetting repository items

Posted: Fri Jul 19, 2013 12:50 pm
by Support Team
Hello,

In general, a rooted folder uses the Base path.
Could you please try the set the Base path instead of the path of your rooted folder?
RepoPath.VariableTab.SelfInfo.BasePath = "container["+i+"]";
Regards,
Markus (T)

Re: Dynamically resetting repository items

Posted: Fri Jul 19, 2013 4:41 pm
by KurtZ
BasePath exists on the folder object itself, as opposed to the SelfInfo object, but this solved both issues.
Thanks Rano team, you all rock!
RepoPath.container_VariableTab.BasePath = "container["+i+"]";