Highlighted

Inserting Multiple instances into a databse

Aditya_S_

16-01-2009

I am using MySQL to capture the form data. In the form I have a Driver License section which can have multiple instances.



In the workflow I am using the "Execute SQL query" module to insert data. Initially I can insert information from the non-repeating subforms, successfully. However, workflow inserts no information from repeating subforms. Below is an example of the XPATH used.



/process_data/xfaform/object/data/xdp/datasets/data/App/DriverLicense/drvlicstate



Is the above format correct ? How can I insert the second and third instances ?



Thanks

Aditya

Replies

Highlighted

Jasmin_Charbonn

19-01-2009

You would need to call the "Execute SQL query" a second time and pass the information for the second driver licence section.



Something like /process_data/xfaform/object/data/xdp/datasets/data/App/DriverLicense/drvlicstate[2]



Jasmin
Highlighted

Aditya_S_

20-01-2009

In my workflow, there could be different results of driver license information. Sometimes there could be one or more instances.



Are you suggesting that I will need one SQL query for every instance ? Is there a way to created a loop ?



"Something like /process_data/xfaform/object/data/xdp/datasets/data/App/DriverLicense/drvlicstate[2]"

Just to clarify - would it be the DiverLicense[2] or drvlicstate[2] ? In other words, would I specify the instance on the subform or the field ?



Aditya
Highlighted

Ryan_Lunka

20-01-2009

Yes you can and will have to set up a loop in your process. Use an integer process variable as your loop increment start it at 1 (I'm pretty sure the indexing begins at 1...could be 0). You'll have to use the count() XPath function to count the number of nodes. Something like...



count(/process_data/xfaform/object/data/xdp/datasets/data/App/DriverLicense/drvlicstate)



Compare that number with the index value to know if you've looped through every node (and inserted each, one at a time) or if you need to loop again. Email me and I'd be glad to discuss this further with you if need be. It's not as complicated as it sounds.



Hope this helps!



Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com
Highlighted

Jasmin_Charbonn

20-01-2009

"Just to clarify - would it be the DiverLicense[2] or drvlicstate[2] ? In other words, would I specify the instance on the subform or the field ?"



I think you'll need to get to use DriverLicense to get the count of how many driver licenses you have.



count(/process_data/xfaform/object/data/xdp/datasets/data/App/DriverLicense)



then you can have a loop (just a route coming back to a previous step) that get the value using something like:

/process_data/xfaform/object/data/xdp/datasets/data/App/DriverLicense[i]/drvlicstate



Jasmin