How to Pass Variable/Parameter from User Code to Repository

Ranorex Spy, Recorder, and Studio.
bpomerantz
Posts: 1
Joined: Fri May 23, 2014 1:53 pm

How to Pass Variable/Parameter from User Code to Repository

Post by bpomerantz » Wed Jul 08, 2015 5:38 pm

I am looking to pass a variable from User code to the repository item so that when the Repo item is called, it has the correct row number


The Repository Item is setup with Variable $row_count (/dom//td[#'rptTabs_WebTab_cp']/iframe[@id='rptTabs_WebTab_frame0']//tr[$row_count]/td[62])

Here is the User Code:

Code: Select all

        public void shipment_selection (string row_count)
       public void shipment_selection (string row_count)
        {
        	       	
        	Report.Log(ReportLevel.Info, "Checkboxes", "Gathering information to check the boxes.");
        	int count = 0;
        	int row_count_number = 0;
        	var table_checkboxes = repo.IRRIS.RptTabsWebTabFrame0.table_checkboxesInfo.CreateAdapters<InputTag>();
        	        	
        	foreach(var table_checkbox in table_checkboxes){
        		row_count_number ++;
        		//for(int index = 0; index < repo.IRRIS.RptTabsWebTabFrame0.table_checkboxesInfo.CreateAdapters<InputTag>().Count; index ++) {
       	  		//var table_checkboxes = repo.IRRIS.RptTabsWebTabFrame0.table_checkboxes;
        	if (table_checkbox.Enabled) {
        		table_checkbox.Click(); 
        	
        		row_count = row_count_number.ToString();
                Report.Log(ReportLevel.Info, "User Code", row_count, new RecordItemIndex(1));
                

        	//Adding getting Lat/Long
//        	Report.Log(ReportLevel.Info, "Get Value", "Getting attribute 'InnerText' from item 'IRRIS.RptTabsWebTabFrame0.Latitude' and assigning its value to variable 'var_latitude'.", repo.IRRIS.RptTabsWebTabFrame0.LatitudeInfo, new RecordItemIndex(0));
//            var_latitude = repo.IRRIS.RptTabsWebTabFrame0.Latitude.Element.GetAttributeValueText("InnerText");
//            Report.Log(ReportLevel.Info, "Get Value", "Getting attribute 'InnerText' from item 'IRRIS.RptTabsWebTabFrame0.Longitude' and assigning its value to variable 'var_longitude'.", repo.IRRIS.RptTabsWebTabFrame0.LongitudeInfo, new RecordItemIndex(0));
//            var_longitude = repo.IRRIS.RptTabsWebTabFrame0.Longitude.Element.GetAttributeValueText("InnerText");
//            Report.Log(ReportLevel.Info,"Latitdude is ",var_latitude);
//            Report.Log(ReportLevel.Info,"Longitude is ",var_longitude);
//            Delay.Milliseconds(0);
//            
           
            //END GETTING LAT/LONG
            
        		count ++;
        	}
       	  	if (count==1)
       	  		{break;}
Within the User Code row_count has the correct value but the repository still does not have the correct value. And once the user code is done, then row_count no longer has the correct value.

How can I pass the row_count out of the user code so that the repository can use it?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to Pass Variable/Parameter from User Code to Repository

Post by Support Team » Thu Jul 09, 2015 8:30 am

Hello bpomerantz,

The problem might be that you assigned the current row count value only to your local row_count variable. If you have defined a path which contains a repository variable this variable is part of the repository.

Therefore, you have to create an object of your current repository instance and set the value for the repository variable before you can perform any click operations on specific rows.

If the row_count is not set up explicitly, the default value will be used for the Xpath. Below you will find an example how you can create your repository object within the code and set the corresponding value.

Code: Select all

ExampleRepository repo = ExampleRepository.Instance;

repo.row_count = <row_count value>;
Please let us know if this solves your issue.

Regards,
Johannes
.
Image