Check boxes in a repeating table - InfoPath Dev Sign in | Join | Help in Newbie Questions InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Newbie Questions » Check boxes in a repeating table Check boxes in a repeating table Last post 08-01-2008 03:23 PM by mjaneczk. 14 replies. Page 1 of 1 (15 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 07-30-2008 12:25 PM mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Check boxes in a repeating table Reply Contact I found a post which got me most of the way to where I need, but not close enough for me, espeically since I am relatively new. I need a repeating table which reads from a SharePoint List. In each of the rows I need a checkbox which would allow the user to de/select that row. Upon pressing a button, I need the form to write the selected rows to a list. I am able to create the repeating table which reads from the SharePoint List, and create the select box [I got this to work by creating a Yes/No column in my SP list called "select", so when I created my repeating table I get the check box). So, my problem now is how to loop through the selected items and write those to another SP list. I beleive I have to write some code to do this; I am new to C#, but not to coding (Java) so this doesn't scare me. My problem is that I don't know the object model well enough to know where to begin. Does someone have a code snippet from which I can being? If it would take too long to write a snippet, what object/methods would I use, and I can do the code, and report the solution back here. BTW, I also need a "select all" checkbox, which I assume I will be able to develop using the code snippet from above. If not, can I get a snippet of that too? Mike JaneczkoFord Motor Company Filed under: repeating table 07-31-2008 01:55 PM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact The form needs to use InfoPath 2003, but my development environment is InfoPath 2007. (long story). I am using VTSA with C#. I have found a basic snippet based on a bunch of reading, so I got past that problem, now I have a new problem. The snippet is here: IXMLDOMDocument2 oSecondDoc = thisXDocument.DOM as IXMLDOMDocument2;oSecondDoc.setProperty("SelectionNamespaces", "xmlns:ns1=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'"); IXMLDOMNodeList nodes = oSecondDoc.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Provisioning_Forms"); foreach (IXMLDOMNode node in nodes){ thisXDocument.UI.Alert(node.text); } This code throws the error: Reference to undeclared namespace prefix: 'dfs'. on the underlined line. I am stumped. If I can get to this data source, then I can loop through the selection fields and accomplish both a "select all" button and to write it to a selected list. So, to save my last nerve, please help! Mike JaneczkoFord Motor Company 07-31-2008 02:19 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact Hi, Mike: In this line, you are setting the namespace to ns1: oSecondDoc.setProperty("SelectionNamespaces", "xmlns:ns1=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'"); But in your XPath to your note, your namespace is dfs: IXMLDOMNodeList nodes = oSecondDoc.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Provisioning_Forms"); One of them has to change. If your XPath is right then your namespace when you set the property on oSecondDoc is wrong. You can extract your form files to find your namespaces -- or just change the line to this: oSecondDoc.setProperty("SelectionNamespaces", "xmlns:dfs=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'"); That's what it is in a form of mine built off a data source. Hilary Stoupa 08-01-2008 07:47 AM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact Hi Hillary, I changed the code to look liek the last line you suggested and it that works. My code looks like: IXMLDOMDocument2 oSecondDoc = thisXDocument.DOM as IXMLDOMDocument2; oSecondDoc.setProperty("SelectionNamespaces","xmlns:dfs=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");IXMLDOMNodeList nodes = oSecondDoc.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Provisioning_Forms"); thisXDocument.UI.Alert(nodes.length.ToString());foreach (IXMLDOMNode node in nodes) { thisXDocument.UI.Alert(node.text); } Now I am off to my next challenge. The Alert I put up to find the number of nodes is 0. Yet when I display the repeating table it has 2 rows. Mike JaneczkoFord Motor Company 08-01-2008 08:14 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact Quadruple check your XPath -- that is where I usually go astray. Make sure your spelling and capitalization is dead on, XPath is really finicky like that. Hilary Stoupa 08-01-2008 10:11 AM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact In design mode of InfoPath, I right clicked the portion of the data source I wanted and selected "Copy XPath". Then pasted it into the code. Are there problems with doing it that way? This data source is a Secondary Data Source. My Data Source window looks like: My Fields dataFields Provisioning_Forms Requestor Approver Dept_Code Disposition Mike JaneczkoFord Motor Company 08-01-2008 11:10 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact Ah ha! Okay, first off, copying XPath from the data source task pane is exactly the right way to go -- because that way you don't have to worry about mistakes. That isn't availble in IP2003 and I wasn't sure which version you were using. However, you are accessing the main DOM of your document. You need to access your secondary data connection. This: IXMLDOMDocument2 oSecondDoc = thisXDocument.DOM as IXMLDOMDocument2; should be: IXMLDOMDocument2 oSecondDoc = thisXDocument.GetDOM("SecondaryDataConnectionName") as IXMLDOMDocument2; The secondary data connection name is passed into GetDOM. Hilary Stoupa 08-01-2008 11:28 AM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact I really appreciate your help! I put in the secondary data connection name and it is retruning no data. I have data in the form's corresponding repeating table, but when I loop through the nodes, I get nothing. I but in an Alert to show the length and it is 0. Do I need to bind this to the external Data Source? Maybe this will help, below is a screen shot of my form. The data is read from a SharePoint Library, hence a secondary data source. So there is data there. When I click Select all which runs the code above with all your corrections included, the number of nodes is 0. Mike JaneczkoFord Motor Company 08-01-2008 12:26 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact So, off the subject of code entirely -- if all you need to do is set all those check boxes to true, you can do that with a rule. On your button, add a rule. Select Set a field's value, put in the field related to the checkbox in your select column and put in True for the value. If that doesn't work, right click your check box, look at the properties, and see what the values are (if it is a lower case "t" in true, for example, or if the word is all upper case). As far as why you are returning no data -- generally for me, it is because my XPath is wrong, my Data Connection name is wrong, or my namespace is wrong.... I wish I could help you pinpoint it a bit better than that.... Hilary Stoupa 08-01-2008 12:38 PM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact Adding a rule would work for select all, but there is another thing I need to do which would use the same code. I was going to Add yet another button which would loop through all the rows and submit them to a list depending on a column value. Can I do that in a rule? So this logic would fit two purposes in two separate places. Mike JaneczkoFord Motor Company 08-01-2008 01:00 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact You have a typo: xmlns:dfs=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' Has a space between the single quote and the h in "http" -- see it? Kill the space and try again. Hilary Stoupa 08-01-2008 01:04 PM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact I'm not worthy! I'm not worthy! I would have never of saw that. Thanks a million! For poseterity sake, I will post the code in full. BTW< I did change the data source name in an attempt to see if there was somethign wrong with that. But it works now! IXMLDOMDocument2 oSecondDoc = thisXDocument.GetDOM("PF") as IXMLDOMDocument2; oSecondDoc.setProperty("SelectionNamespaces","xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");IXMLDOMNodeList nodes = oSecondDoc.selectNodes("/dfs:myFields/dfs:dataFields/dfs:PF"); thisXDocument.UI.Alert(nodes.length.ToString());foreach (IXMLDOMNode node in nodes) { thisXDocument.UI.Alert(node.text); } Mike JaneczkoFord Motor Company 08-01-2008 02:14 PM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact I did write a rule for the select all, but when it executes, it doesn't put the checkmark in the box. Is there some way I am supposed to refresh the form afterwards? Mike JaneczkoFord Motor Company 08-01-2008 03:13 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact When I was trying this earlier, my problem was I was setting the field to true (lower case t). If you right clidk on your checkbox and look at the value when checked, your rule that is setting the field's value needs to match that value exactly. To help troubleshoot, temporarily change your checkbox to a text field so you can see what is being set. Hilary Stoupa 08-01-2008 03:23 PM In reply to mjaneczk Joined on 02-18-2008 Dearborn, MI Posts 35 Re: Check boxes in a repeating table Mark as Not AnswerMark as Answer... Reply Contact I was just poking around with what you said, and soemthing weird happened. It works but is weird. I right click and the Value is FALSE" when cleared, and "TRUE" when checked (all caps). In my rule, I set the value to "true" (all lower) when checked, and it does what I want. Weird, but oh well it works! Thanks again! Mike JaneczkoFord Motor Company Page 1 of 1 (15 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
I found a post which got me most of the way to where I need, but not close enough for me, espeically since I am relatively new.
I need a repeating table which reads from a SharePoint List. In each of the rows I need a checkbox which would allow the user to de/select that row. Upon pressing a button, I need the form to write the selected rows to a list. I am able to create the repeating table which reads from the SharePoint List, and create the select box [I got this to work by creating a Yes/No column in my SP list called "select", so when I created my repeating table I get the check box). So, my problem now is how to loop through the selected items and write those to another SP list. I beleive I have to write some code to do this; I am new to C#, but not to coding (Java) so this doesn't scare me. My problem is that I don't know the object model well enough to know where to begin. Does someone have a code snippet from which I can being? If it would take too long to write a snippet, what object/methods would I use, and I can do the code, and report the solution back here.
BTW, I also need a "select all" checkbox, which I assume I will be able to develop using the code snippet from above. If not, can I get a snippet of that too?
The form needs to use InfoPath 2003, but my development environment is InfoPath 2007. (long story). I am using VTSA with C#.
I have found a basic snippet based on a bunch of reading, so I got past that problem, now I have a new problem. The snippet is here:
thisXDocument.UI.Alert(node.text);
}
This code throws the error: Reference to undeclared namespace prefix: 'dfs'. on the underlined line. I am stumped. If I can get to this data source, then I can loop through the selection fields and accomplish both a "select all" button and to write it to a selected list. So, to save my last nerve, please help!
Hi, Mike:
In this line, you are setting the namespace to ns1:
oSecondDoc.setProperty("SelectionNamespaces", "xmlns:ns1=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");
But in your XPath to your note, your namespace is dfs:
IXMLDOMNodeList nodes = oSecondDoc.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Provisioning_Forms");
One of them has to change. If your XPath is right then your namespace when you set the property on oSecondDoc is wrong. You can extract your form files to find your namespaces -- or just change the line to this:
oSecondDoc.setProperty("SelectionNamespaces", "xmlns:dfs=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");
That's what it is in a form of mine built off a data source.
Hi Hillary,
I changed the code to look liek the last line you suggested and it that works. My code looks like:
oSecondDoc.setProperty(
thisXDocument.UI.Alert(nodes.length.ToString());
{
Now I am off to my next challenge. The Alert I put up to find the number of nodes is 0. Yet when I display the repeating table it has 2 rows.
Quadruple check your XPath -- that is where I usually go astray. Make sure your spelling and capitalization is dead on, XPath is really finicky like that.
In design mode of InfoPath, I right clicked the portion of the data source I wanted and selected "Copy XPath". Then pasted it into the code. Are there problems with doing it that way? This data source is a Secondary Data Source.
My Data Source window looks like:
My Fields
dataFields Provisioning_Forms Requestor Approver Dept_Code Disposition
dataFields
Provisioning_Forms Requestor Approver Dept_Code Disposition
Provisioning_Forms
Requestor Approver Dept_Code Disposition
Requestor
Approver
Dept_Code
Disposition
Ah ha! Okay, first off, copying XPath from the data source task pane is exactly the right way to go -- because that way you don't have to worry about mistakes. That isn't availble in IP2003 and I wasn't sure which version you were using.
However, you are accessing the main DOM of your document. You need to access your secondary data connection. This:
IXMLDOMDocument2 oSecondDoc = thisXDocument.DOM as IXMLDOMDocument2;
should be:
IXMLDOMDocument2 oSecondDoc = thisXDocument.GetDOM("SecondaryDataConnectionName") as IXMLDOMDocument2;
The secondary data connection name is passed into GetDOM.
I really appreciate your help!
I put in the secondary data connection name and it is retruning no data. I have data in the form's corresponding repeating table, but when I loop through the nodes, I get nothing. I but in an Alert to show the length and it is 0. Do I need to bind this to the external Data Source?
Maybe this will help, below is a screen shot of my form. The data is read from a SharePoint Library, hence a secondary data source. So there is data there. When I click Select all which runs the code above with all your corrections included, the number of nodes is 0.
So, off the subject of code entirely -- if all you need to do is set all those check boxes to true, you can do that with a rule. On your button, add a rule. Select Set a field's value, put in the field related to the checkbox in your select column and put in True for the value. If that doesn't work, right click your check box, look at the properties, and see what the values are (if it is a lower case "t" in true, for example, or if the word is all upper case).
As far as why you are returning no data -- generally for me, it is because my XPath is wrong, my Data Connection name is wrong, or my namespace is wrong.... I wish I could help you pinpoint it a bit better than that....
Adding a rule would work for select all, but there is another thing I need to do which would use the same code. I was going to Add yet another button which would loop through all the rows and submit them to a list depending on a column value. Can I do that in a rule?
So this logic would fit two purposes in two separate places.
You have a typo:
xmlns:dfs=' http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'
Has a space between the single quote and the h in "http" -- see it? Kill the space and try again.
I'm not worthy! I'm not worthy! I would have never of saw that. Thanks a million!
For poseterity sake, I will post the code in full. BTW< I did change the data source name in an attempt to see if there was somethign wrong with that. But it works now!
oSecondDoc.setProperty("SelectionNamespaces","xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");
I did write a rule for the select all, but when it executes, it doesn't put the checkmark in the box. Is there some way I am supposed to refresh the form afterwards?
When I was trying this earlier, my problem was I was setting the field to true (lower case t). If you right clidk on your checkbox and look at the value when checked, your rule that is setting the field's value needs to match that value exactly. To help troubleshoot, temporarily change your checkbox to a text field so you can see what is being set.
I was just poking around with what you said, and soemthing weird happened. It works but is weird.
I right click and the Value is FALSE" when cleared, and "TRUE" when checked (all caps). In my rule, I set the value to "true" (all lower) when checked, and it does what I want. Weird, but oh well it works! Thanks again!