Trying to get previous, next, first and Last record functionality

K

kfrost

I've got a form with several forms. 2 in particular that I'm trying to work
with right now.

The main view has a repeating table which is bound to a secondary data
connection. It connects to a database and brings in a table called Trips.

I have a button column on the left of the table so if a user wants to see
more details about the trip, they click it which brings up more details about
the trip in a view called Trip Details.

I do this by creating a Rule called TripDetails and add 3 actions
1) Set a fields value. I take the Main data connections
Query/datafield/TripID as the field and then for the value you use the TripID
from the secondary source that populates the table
2) Query Using a data Connection, here I use the Primary SQL connection
3) Swithc to View: Trip Details

All of this works great. But I'd like to add |< << >> >| functionality to
be able to move through the records while in the Trip Detail view.

To do this I assume I'm going to have to use the sibling features but I
don't know how to programmatically. if anybody has a sample I would
appreciate it.

Additionally, it appears that I should be able to do this using a rule. The
best I can tell if I could figure out the appropriate XPATH syntax I could
just create the buttons and add rules and the appropriate actions to move
through the records.

I'm trying to set a Set Field value and I'm setting the Field to
Query/datafield/TripID and now I'm trying to set the value. Here's what it
defaults to:
xdXDocument:GetDOM("TripDetails")/dfs:myFields/dfs:dataFields/d:Trips/@TripID

What I'm thinking is I need to figure out how use the preceeding::sibling,
Next, Last() etc to get the preceeding or next values. Anybody know how I
can modify the xpath statement above to get the TripID value in the previous
or next record?

Thanks.

kris
 
K

kfrost

Hello,

Thank you Greg for the response but I couldn't make much sense of the what
that was doing and the buttons didn't appear to function. I reposted this on
your website. I think what I'm doing is fairly simple for somebody that
knows XPath syntax which I do not. Reading up on it now but from what I've
read I think this post brings more clarity to what I'm trying to accomplish.

Hello,

I'm rephrasing a previous post due to no response. I'm trying to figure out
the xpath syntax to get the values from preceding-sibling and
Following-siblings

Say I have a data connection and each set of records returned has a TripID
field. I want to assign a variable the value of the TripID of the
preceding-Sibling or following-Sibling.

Anybody know of how to do this? Here is the syntax to get the current nodes
TripID value.

xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips/@TripID

I would think it would have been something along the lines of:
xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips/../preceding-sibling/@TripID

But I can't figure it out.

Thanks.

kris


Greg Collins said:
This might be helpful:
http://www.infopathdev.com/downloads/free/default.aspx?i=4e0c956598c14f40bc15629faa9c3c32

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



I've got a form with several forms. 2 in particular that I'm trying to work
with right now.

The main view has a repeating table which is bound to a secondary data
connection. It connects to a database and brings in a table called Trips.

I have a button column on the left of the table so if a user wants to see
more details about the trip, they click it which brings up more details about
the trip in a view called Trip Details.

I do this by creating a Rule called TripDetails and add 3 actions
1) Set a fields value. I take the Main data connections
Query/datafield/TripID as the field and then for the value you use the TripID
from the secondary source that populates the table
2) Query Using a data Connection, here I use the Primary SQL connection
3) Swithc to View: Trip Details

All of this works great. But I'd like to add |< << >> >| functionality to
be able to move through the records while in the Trip Detail view.

To do this I assume I'm going to have to use the sibling features but I
don't know how to programmatically. if anybody has a sample I would
appreciate it.

Additionally, it appears that I should be able to do this using a rule. The
best I can tell if I could figure out the appropriate XPATH syntax I could
just create the buttons and add rules and the appropriate actions to move
through the records.

I'm trying to set a Set Field value and I'm setting the Field to
Query/datafield/TripID and now I'm trying to set the value. Here's what it
defaults to:
xdXDocument:GetDOM("TripDetails")/dfs:myFields/dfs:dataFields/d:Trips/@TripID

What I'm thinking is I need to figure out how use the preceeding::sibling,
Next, Last() etc to get the preceeding or next values. Anybody know how I
can modify the xpath statement above to get the TripID value in the previous
or next record?

Thanks.

kris
 
K

kfrost

Ok, I've figured out how to get the last record with the following statement.

xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips[last()]/@TripID

Now I just need to figure out the statements to traverse to the preceding
and following siblings and also first record.

Any input is greatly appreciated.

Thanks.

kris
 
K

kfrost

I finally got this figured out and wanted to post what I came up with for
anybody who has a need for this functionality.

A little explanation.
SQL DB Triplog with Tables Trips and TripDetails

Views
Main
TripDetails

Data Connection
Main (Primary)
Trips (Secondary)

The Main view has a repeating table that is bound to the Trips data
connection. It populates with all the records via the Main Data connection
which pulls all the columns from the Trips table in SQL. Both Trips and
TripDetails tables have a relationship the column TripID. The table has a
button and when clicked it takes the TripID of the trip selected and
populates the main/dfs:myField/dfs:queryField/q:Trips/TripID with the TripID
value of the node from the Trips data connection.

I have four buttons |< << >> >|. For the |< button I created a rule with
that sets the main/dfs:myField/dfs:queryField/q:Trips/TripID with the
following XPath statement:

xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips[position() =
1]/@TripID
Also, to this I add the action of:
Query using a data connection: (Main)


For the >| button I use this Xpath function:
xdXDocument:GetDOM("Trips")/dfs:myFields/dfs:dataFields/d:Trips[last()]/@TripID
Again I add the action:

Query using a data connection: (Main)

For functionality for the << button, I use the code below. Note for the >>
button I use the same code with the exception of changing preceding-sibling
string with:
"following-sibling::d:Trips[1]"

I'm not sure this is the best way to go about doing this but I ended up
patterning it after the code in the Data Interop example from the SDK.


Public Sub btnPrecedingTrip_OnClick(ByVal e As DocActionEvent)
' Write your code here.
' Here we need to get the TripID attribute of the trip selected
and assign it to
' gstrTripID to use to traverse through the records.
Dim objPrecTripElem As IXMLDOMElement
Dim objTripsElem As IXMLDOMElement
Dim objMainElem As IXMLDOMElement
Dim objQueryElem As IXMLDOMElement
Dim gstrTripID As String

' First we have to get the TripID of the Trip in which details are being
viewed
objMainElem = thisXDocument.DOM.selectSingleNode("//Trips")
gstrTripID = objMainElem.getAttribute("TripID")

' Here we are going to set a doc object to the Trips Data connection with
the matching TripID
Dim objTripsNode As IXMLDOMDocument3 =
DirectCast(thisXDocument.GetDOM("Trips"), IXMLDOMDocument3)

objTripsNode.setProperty("SelectionNamespaces",
"xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution""
xmlns:d=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields""")

objTripsElem =
objTripsNode.selectSingleNode("dfs:myFields/dfs:dataFields/d:Trips[string(@TripID)='" + gstrTripID + "']")

' Here we are getting the preceding sibling's TripID value
objPrecTripElem =
objTripsElem.selectSingleNode("preceding-sibling::d:Trips[1]")

If (objPrecTripElem Is Nothing) Then
thisXDocument.UI.Alert("This is the first Record.")
Else
Dim strID As String = objPrecTripElem.getAttribute("TripID")
objQueryElem =
thisXDocument.DOM.selectSingleNode("dfs:myFields/dfs:queryFields/q:Trips")
objQueryElem.setAttribute("TripID", strID)
thisXDocument.Query()
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top