Copy field values in Repeating Section - InfoPath Dev Sign in | Join | Help in Qdabra qRules Qdabra Software Product Support (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 » Qdabra Software Product Support » Qdabra qRules » Copy field values in Repeating Section Copy field values in Repeating Section Last post 12-14-2010 10:36 AM by greenawayr. 23 replies. Page 1 of 2 (24 items) 1 2 Next > Sort Posts: Oldest to newest Newest to oldest Previous Next 12-06-2010 09:16 AM greenawayr Joined on 05-05-2009 Posts 52 Copy field values in Repeating Section Reply Contact Hi,I've just installed the trial of qrules to see if it can help with a problem I'm having. I'm sure it should be simple enough but I'm not seeing a solution yet so hoping someone can point me in the right direction.I have a form with a Client repeating section, all I want is for a button that allows our user to copy across the address fields from Client 1, to Client 2, if they've added a second section. The address fields are just a selection of the bigger group, so I need to specify which fields to copy and where to paste. It's a browser enabled form that has some code behind already but I've injected qRules into it ok.A lot of the examples I'm seeing for similar things to this are using secondary data sources and copying to the main datasource, whereas I'm just looking to copy from within the same repeating group.I would most likely be creating a button within the repeating section, so that when the second, or third client is added, the button copies the address from the primary client (if I get my head around this and qRules, then I might get adventurous and allow them to select which clients address to copy, but for now, I just want to get to work with qRules).ANy help you can give me with this is greatly appreciated. Filed under: qrules, repeating section 12-06-2010 12:59 PM In reply to ErnestoM Joined on 08-27-2007 Posts 3,320 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Using CopyTable and Insert with the main data source is no different that using the commands with the secondary data sources as displayed in our examples. You may want to take a look at the Insert command (see this document). If you're running into issues it might be useful to get an idea of your data source, to understand your source and destination and help you out with the necessary command. You can attach screenshots to the forum posts via the Options tab when replying. Ernesto MachadoQdabra® Software/ InfoPathDev.comThe InfoPath Experts – Streamline data gathering to turn process into knowledge.™ 12-07-2010 08:08 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section datasource.JPG Mark as Not AnswerMark as Answer... Reply Contact Thank you Ernesto.Below is a screenshot of my datasource, with the repeating table that I wish to copy being Clients. This main datasource is received from a webservice. The fields I would want to copy are selected from the list to the right of the attachment, these would be the CustAddress1,2,3,4,5 and CustPostcode. As I said before, I'm just looking to copy from the first instance of the repeating section to the last instance, or if I put the button in the repeating section, then whichever I want to copy from the first instance to the instance that the button exists in.Thanks 12-07-2010 09:13 AM In reply to ErnestoM Joined on 08-27-2007 Posts 3,320 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Hi Ryan,If you're just copying one field into another, then a rule might be enough (i.e. Set a field's value).CopyTable will copy the entire table (which doesn't sound like what you're trying to accomplish). The command Insert might help, since it can take a value and insert it into another xpath. So, to be clear, you want to take CustAddress1,2,3,4,5 and CustPostCode from one row in the repeating table and copy the values into another row in the repeating table - is that correct? Thanks. Ernesto MachadoQdabra® Software/ InfoPathDev.comThe InfoPath Experts – Streamline data gathering to turn process into knowledge.™ 12-07-2010 09:23 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Yes that's correct.By rule, do you mean simply setting a fields value as itself as a normal rule on a button click event? As I've tried that with no luck unless I'm doing something wrong. I assumed qRules was needed to specify which row you were copying to and from.Thanks again 12-07-2010 09:41 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact InfoPath doesn't let us specify which field in a repeating table we want to copy to, so that's an issue. qRules does -- the command you'll want is SetValue. For example: concat("SetValue /xpath=my:myFields/my:group1/my:group2/my:field4[../my:field3='", field1, "'] /value=", field2) You may need to combine count with preceeding-sibling to get the correct index of your current group for the XPath filter for the /xpath parameter if the button is inside the target group. For the /value, you'd use the full XPath to the field you want the value from and can either specify that you want the first instance of the group by adding [1] to the repeating group, or you can leverage the fact that by default IP will pick the first one. concat("SetValue /xpath=<path to ns1:dsforms>/Clients[," <formula to get the correct index of the current group>, "]/CustAddress1 /value=", <path to ns1:dsforms>/Clients[1]/CustAddress1) Hilary Stoupa 12-08-2010 07:55 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact As you can see below, I'm a little stumped on the bit about the count function I haven't done much in the way of complicated formulas in the rules, so am a little confused about this and where things should go. I tried - count(preceeding-sibling::Clients) - but this returned an error and I'm not even sure I'm putting this in the right place. I created a button and a rule for it's click, Set a Fields Value, but then I'm stumped as to what I do with the snippets you gave me, as looking at the code, it looks like I'm selecting the "Field" and the "Value", so is this in fact meant to be placed in code behind for the Buttons click event or am I getting confused here? This is what I assume I should have (minus the count formula obviously), could you tell me where I've gone wrong with this, and then where I need to put it, or split it, or have I just been staring at a screen for too long and am missing the obvious! concat("SetValue /xpath=</dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[," <SORRY I'M LOST HERE>, "]/CustAddress1 /value=", </dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms>/Clients[1]/CustAddress1) Thanks 12-08-2010 10:34 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Any chance you can attach your template to a reply? Under the Options tab is a place to attach a file.... Hilary Stoupa 12-09-2010 01:54 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section NBSForm.xsn Mark as Not AnswerMark as Answer... Reply Contact Tada! Thanks 12-09-2010 07:50 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact count(preceding::ns1:Clients) + 1 will get you the index of the current client section in the rule on your button. Hilary Stoupa 12-09-2010 08:49 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact So I have the following Action - Set a fields value Field - Command Value - concat("SetValue /xpath=</dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[," <count(preceding::ns1:Clients) + 1>, "]/CustAddress1 /value=", </dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms>/Clients[1]/CustAddress1) but no joy. Clearly doing something stupid here. 12-09-2010 09:06 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Your XPaths are incorrect, and I'm seeing some odd characters in them. The original <> marks were to indicate place holders. concat("SetValue /xpath=dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[," count(preceding::ns1:Clients) + 1, "]/ns1:CustAddress1 /value=", dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[1]/ns1:CustAddress1) Be sure while testing you have the QdabraRules error node visible somewhere in your form -- you'll want to be able to see any error messages. Hilary Stoupa 12-09-2010 09:37 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Thanks for that, I didn't realise that about the error node. It's giving me this An error has occurred executing the rule. Invalid command specified: concat 12-09-2010 09:42 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact The formula needs to go into the formula editor. Next to the value box in the rule action is a button that looks like this: fx Click that button, then paste your formula in the editor box. Hilary Stoupa 12-10-2010 07:29 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Copy field values in Repeating Section Mark as Not AnswerMark as Answer... Reply Contact Sorry to be a pain but I'm getting this error when I check the formula Expected value type: , Actual value: nameconcat("SetValue /xpath=dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[, " -->count<--(preceding::ns1:Clients) + 1, "]/ns1:CustAddress1 /value=", dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[1]/ns1:CustAddress1) I've tried messing around with this and putting comma's in different places around this count function, but as yet, no joy! Page 1 of 2 (24 items) 1 2 Next > Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
Hi,
I've just installed the trial of qrules to see if it can help with a problem I'm having. I'm sure it should be simple enough but I'm not seeing a solution yet so hoping someone can point me in the right direction.
I have a form with a Client repeating section, all I want is for a button that allows our user to copy across the address fields from Client 1, to Client 2, if they've added a second section. The address fields are just a selection of the bigger group, so I need to specify which fields to copy and where to paste. It's a browser enabled form that has some code behind already but I've injected qRules into it ok.
A lot of the examples I'm seeing for similar things to this are using secondary data sources and copying to the main datasource, whereas I'm just looking to copy from within the same repeating group.
I would most likely be creating a button within the repeating section, so that when the second, or third client is added, the button copies the address from the primary client (if I get my head around this and qRules, then I might get adventurous and allow them to select which clients address to copy, but for now, I just want to get to work with qRules).
ANy help you can give me with this is greatly appreciated.
Using CopyTable and Insert with the main data source is no different that using the commands with the secondary data sources as displayed in our examples. You may want to take a look at the Insert command (see this document). If you're running into issues it might be useful to get an idea of your data source, to understand your source and destination and help you out with the necessary command. You can attach screenshots to the forum posts via the Options tab when replying.
Thank you Ernesto.
Below is a screenshot of my datasource, with the repeating table that I wish to copy being Clients. This main datasource is received from a webservice. The fields I would want to copy are selected from the list to the right of the attachment, these would be the CustAddress1,2,3,4,5 and CustPostcode.
As I said before, I'm just looking to copy from the first instance of the repeating section to the last instance, or if I put the button in the repeating section, then whichever I want to copy from the first instance to the instance that the button exists in.
Thanks
Hi Ryan,
If you're just copying one field into another, then a rule might be enough (i.e. Set a field's value).
CopyTable will copy the entire table (which doesn't sound like what you're trying to accomplish).
The command Insert might help, since it can take a value and insert it into another xpath.
So, to be clear, you want to take CustAddress1,2,3,4,5 and CustPostCode from one row in the repeating table and copy the values into another row in the repeating table - is that correct?
Thanks.
Yes that's correct.
By rule, do you mean simply setting a fields value as itself as a normal rule on a button click event? As I've tried that with no luck unless I'm doing something wrong. I assumed qRules was needed to specify which row you were copying to and from.
Thanks again
InfoPath doesn't let us specify which field in a repeating table we want to copy to, so that's an issue. qRules does -- the command you'll want is SetValue.
For example:
concat("SetValue /xpath=my:myFields/my:group1/my:group2/my:field4[../my:field3='", field1, "'] /value=", field2)
You may need to combine count with preceeding-sibling to get the correct index of your current group for the XPath filter for the /xpath parameter if the button is inside the target group. For the /value, you'd use the full XPath to the field you want the value from and can either specify that you want the first instance of the group by adding [1] to the repeating group, or you can leverage the fact that by default IP will pick the first one.
concat("SetValue /xpath=<path to ns1:dsforms>/Clients[," <formula to get the correct index of the current group>, "]/CustAddress1 /value=", <path to ns1:dsforms>/Clients[1]/CustAddress1)
As you can see below, I'm a little stumped on the bit about the count function
I haven't done much in the way of complicated formulas in the rules, so am a little confused about this and where things should go.
I tried - count(preceeding-sibling::Clients) - but this returned an error and I'm not even sure I'm putting this in the right place.
I created a button and a rule for it's click, Set a Fields Value, but then I'm stumped as to what I do with the snippets you gave me, as looking at the code, it looks like I'm selecting the "Field" and the "Value", so is this in fact meant to be placed in code behind for the Buttons click event or am I getting confused here?
This is what I assume I should have (minus the count formula obviously), could you tell me where I've gone wrong with this, and then where I need to put it, or split it, or have I just been staring at a screen for too long and am missing the obvious!
concat("SetValue /xpath=</dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[," <SORRY I'M LOST HERE>, "]/CustAddress1 /value=", </dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms>/Clients[1]/CustAddress1)
Any chance you can attach your template to a reply? Under the Options tab is a place to attach a file....
Tada!
count(preceding::ns1:Clients) + 1 will get you the index of the current client section in the rule on your button.
So I have the following
Action - Set a fields value
Field - Command
Value - concat("SetValue /xpath=</dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[," <count(preceding::ns1:Clients) + 1>, "]/CustAddress1 /value=", </dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms>/Clients[1]/CustAddress1)
but no joy. Clearly doing something stupid here.
Your XPaths are incorrect, and I'm seeing some odd characters in them. The original <> marks were to indicate place holders.
Be sure while testing you have the QdabraRules error node visible somewhere in your form -- you'll want to be able to see any error messages.
Thanks for that, I didn't realise that about the error node. It's giving me this
An error has occurred executing the rule. Invalid command specified: concat
The formula needs to go into the formula editor. Next to the value box in the rule action is a button that looks like this: fx
Click that button, then paste your formula in the editor box.
Sorry to be a pain but I'm getting this error when I check the formula
Expected value type: ,
Actual value: nameconcat("SetValue /xpath=dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[, " -->count<--(preceding::ns1:Clients) + 1, "]/ns1:CustAddress1 /value=", dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Clients[1]/ns1:CustAddress1)
I've tried messing around with this and putting comma's in different places around this count function, but as yet, no joy!