Highlighted
Absent Member.
Absent Member.
930 views

how to select parent and child from weblist and add to datatable

Jump to solution

I have a weblist which has parent and child, i need to add the parent and child in different columns in datable.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Knowledge Partner
Knowledge Partner

Re: how to select parent and child from weblist and add to datatable

Jump to solution

Here you are setting i+1 but you are then not iterating i for further loops of j so you are always writing to row 4

 DataTable.GetSheet("Customer").SetCurrentRow(i+1)

Within your j loop and after the above statement you need to add an i = i+ 1

What I would do is at the start of your routine drop the i loop you don't need it, do something like:

i = DataTable.GetSheet("Global").GetRowCount

i = i + 1

Then amend your SetCurrentRow to and iterate i after it

 DataTable.GetSheet("Customer").SetCurrentRow(i)

i = i + 1

 

Mark Smith.

View solution in original post

6 Replies
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: how to select parent and child from weblist and add to datatable

Jump to solution

What's the issue here? Can you add more details?

_____________________
Rajkumar Rajangam
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: how to select parent and child from weblist and add to datatable

Jump to solution

i need to populate the datatable as parent in one column and the corresponding child in another colum, but when trying to increment the rows in datatable it does for the first and second row, from second row onwards it is overwriting the exisiting row. 

i got the rowcount of the datatable using getrowcount and in my for loop i gave as rowcount + 1

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: how to select parent and child from weblist and add to datatable

Jump to solution
Can you post your code?

Guess there's something wrong with the row increment. Are you setting the next row using SetCurrentRow method?
_____________________
Rajkumar Rajangam
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: how to select parent and child from weblist and add to datatable

Jump to solution

irow = DataTable.GetSheet("Customer").GetRowCount
For i = 1 To irow
datatable.SetCurrentRow(i) 

Next

result = qtp_GetROProperty( defaultPage.WebList("FromList"), "items count", itemsCount) 

For j = 1 to itemsCount

sMainstring = defaultpage.WebList("FromList")).GetItem(j) 
 
sSubstring = Left(sMainstring, 2)
 
If sSubstring = "  " Then
  
 DataTable.Value("Child", "Customer") = sMainstring
 DataTable.GetSheet("Customer").SetCurrentRow(i+1)
 else
  
  DataTable.Value("Parent","Customer") = sMainstring
End if
Next

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: how to select parent and child from weblist and add to datatable

Jump to solution

Here you are setting i+1 but you are then not iterating i for further loops of j so you are always writing to row 4

 DataTable.GetSheet("Customer").SetCurrentRow(i+1)

Within your j loop and after the above statement you need to add an i = i+ 1

What I would do is at the start of your routine drop the i loop you don't need it, do something like:

i = DataTable.GetSheet("Global").GetRowCount

i = i + 1

Then amend your SetCurrentRow to and iterate i after it

 DataTable.GetSheet("Customer").SetCurrentRow(i)

i = i + 1

 

Mark Smith.

View solution in original post

Highlighted
Absent Member.
Absent Member.

Re: how to select parent and child from weblist and add to datatable

Jump to solution

Thanks it works perfectly.

i have one more question, Suppose a parent has five children how to have values in the datatable as for each child it should have the parent in the next column.  Now i am getting the datatable populated as parent-child1, child 2, child3 etc.  Only the first child has parent associated with it, the rest is populated as a branch of the parent.

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.