Displaying a State(as in the United States) Based on the beginning of an Account number - 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 » Displaying a State(as in the United States) Based on the beginning of an Account number Displaying a State(as in the United States) Based on the beginning of an Account number Last post 08-28-2009 05:26 AM by kingspeget. 16 replies. Page 1 of 2 (17 items) 1 2 Next > Sort Posts: Oldest to newest Newest to oldest Previous Next 08-13-2009 05:37 AM kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Displaying a State(as in the United States) Based on the beginning of an Account number Reply Contact What I need to figure out is how to do this: When a user enters an account number, I need another control box to return the State(as in the United States) that is associated with the first 5 numbers of that account number (the System or "SysPrin"). I have an XML file (pictured below) that lists the SysPrin with the corresponding state loaded into my InfoPath document. Try as I might, I cannot figure out the syntax to setup a rule to return the sibling node of the SysPrin for the corresponding account number. I haven't written any code in years, and I only started to learn back then. I would appreciate any help you could offer. --------------------------------------------------------------------------------------------------------------------------------------------------------------------- I Think, Therefore Someone Wrote the Code Comanding Me To Do So Filed under: xml, xpath, sibling 08-13-2009 07:10 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact Thanks for providing a screenshot of the XML format. That's very helpful.Placing a default value on the state field might be the way to go. Try setting its default value to this formula:xdXDocument:GetDOM("Secondary data source name")/Row[SysPrin = substring(xdXDocument-get-DOM()/path to account name in main data source, 1, 5)]/State Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 08-13-2009 08:53 AM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact I want to start off by thanking you for your assistance Jimmy. However, the code is generating an error. Your Code SuggestionxdXDocument:GetDOM("Secondary data source name")/Row[SysPrin = substring(xdXDocument-get-DOM()/path to account name in main data source, 1, 5)]/State Code Suggestion w/ data insertedxdXDocument:GetDOM("Systems by SysPrin")/Row[SysPrin = substring(xdXDocument-get-DOM()/my:account, 1, 5)]/State Error Generated'xdXDocument-get-DOM' is not a valid XSLT or XPath function.xdXDocument:GetDOM("Systems by SysPrin")/Row[SysPrin = substring(-->xdXDocument-get-DOM()<--/my:account, 1, 5)]/State I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-13-2009 09:03 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact My mistake. That should be a colon before get-DOM(), not a hyphen:xdXDocument:get-DOM()But I'm dubious about the rest of that path. You need the to use the full path to the my:account node, e.g. my:myFields/yaddah yaddah/my:account, paying close attention to capitalization. Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 08-13-2009 12:15 PM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact xdXDocument:GetDOM("Systems by SysPrin")/Root/Row[SysPrin = substring("8XXXXXXXXXXXXX", 1, 8)]/State This line of code works. however, i cannot get it to take the data from the account field. Path i used to point the the account text box: /my:CoachingOp/my:SetArea/my:account Is there a certian type of data it has to be (double, string, interger)? I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-13-2009 04:58 PM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact It seems you have edited your post, but in a previous version of your post I saw that you had the path in quotation marks (i.e. "/my:CoachingOp/my:SetArea/my:account"). It should not be in quotation marks.I'm 95% sure it's a problem with your path to the my:account field. Could you post a screenshot of your main data source layout (from the taskpane)? Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 08-14-2009 07:07 AM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact im pretty sure you are right about that I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-14-2009 09:01 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact That's not your main data source. Could you change the dropdown there to show me the data source that includes my:account? Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 08-14-2009 10:19 AM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact But that would have made sense? why would i have done that? Sorry, skipped the morning coffie earlier I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-14-2009 06:55 PM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact Thank you. Yes, it looks like my:CoachingOp/my:SetArea/my:account is probably the right path. Did you try putting it all together with get-DOM() and everything?xdXDocument:GetDOM("Systems By SysPrin")/Row[SysPrin = substring(xdXDocument-get-DOM()/my:CoachingOp/my:SetArea/my:account, 1, 8)]/State my: might not be the correct namespace if you're basing the form off of a pre-made schema. If the above doesn't work, you can right-click account in the taskpane and pick Copy XPath to find the XPath that InfoPath is expecting. Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 08-18-2009 12:45 PM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact The Error im getting now is:Function 'GetDOM' did not return a value, or it returned a value that cannot be converted to an XSL data type. I get this error if I delete everything exept GetDOM("Systems By SysPrin") from the function box as well. This leads me to believe there is something wrong with my XML source document. It may be in how I made it. What I did was create a 3 column table in Excel with SysPrin, State,and KMA as the titles for each Colum, then converted it to XML I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-19-2009 01:07 PM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact If im looking for the sibling of a note, wouldnt the syntax look more like this: xdXDocument:GetDOM("Systems By SysPrin")/Root/Row[SysPrin = substring(xdXDocument:get-DOM()/my:CoachingOp/my:SetArea/my:account, 1, 8)]/following-sibling::Systems//Root/Row/State I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-19-2009 03:50 PM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact No, I don't think that would be right. That would be make some sense if Row had a sibling called Systems, but I don't see a node called Systems anywhere in your data source. At the point where your red text starts, the XPath is positioned at a Row node assuming the filter found something. And the desired State node is right under the Row node. Are you still getting that error you mentioned? That seems strange because you said that this one worked, albeit without the full functionality you want of course: xdXDocument:GetDOM("Systems by SysPrin")/Root/Row[SysPrin = substring("8XXXXXXXXXXXXX", 1, 8)]/State Is it perhaps that your XML data source is not set to "query when the form is opened"? Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 08-25-2009 12:31 PM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact It is set to query when the form is opened, i reloaded it to doublecheck and i should have noted that i changed the name of the XML doc to "System" from "Systems by sys prin" to make it easier for me to test my code correct me if im wrong, but if it displays the State when i enter in the account number manualy, but not when the users enter it in the my:account field, wouldnt that mean that the XML doc is loaded fine because it displayed the State in the first place, and the problem was with the path to the my:account field? I Think, Therefore Someone Wrote the Code Comanding Me To Do So 08-27-2009 09:58 AM In reply to kingspeget Joined on 08-12-2009 Louisville, KY (USA) Posts 12 Re: Displaying a State(as in the United States) Based on the beginning of an Account number Mark as Not AnswerMark as Answer... Reply Contact well, in all my infinite glory, i found what the problem was. When i began trying to figure out the solution on my own before i started posting here, i had a rule setup in the account field, once i removed that rule, the code you taught me worked absolutely perfect! I want to thank you agian for all your help and putting up with a newbie like me.With that being said, i have one final question:some of the SysPrins have part of the sysprin at the begining of the number, and part at the end. i want to use substring to strip both parts and ad them together, not as in addition, but at in one after the other, into a new number, i just have no idea what operator i would useCode:substring(account, 1, 3) ? substring(account, 13, 6) I Think, Therefore Someone Wrote the Code Comanding Me To Do So Page 1 of 2 (17 items) 1 2 Next > Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
I haven't written any code in years, and I only started to learn back then. I would appreciate any help you could offer.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks for providing a screenshot of the XML format. That's very helpful.
Placing a default value on the state field might be the way to go. Try setting its default value to this formula:
xdXDocument:GetDOM("Secondary data source name")/Row[SysPrin = substring(xdXDocument-get-DOM()/path to account name in main data source, 1, 5)]/State
Your Code Suggestion
Code Suggestion w/ data inserted
My mistake. That should be a colon before get-DOM(), not a hyphen:
xdXDocument:get-DOM()
But I'm dubious about the rest of that path. You need the to use the full path to the my:account node, e.g. my:myFields/yaddah yaddah/my:account, paying close attention to capitalization.
xdXDocument:GetDOM("Systems by SysPrin")/Root/Row[SysPrin = substring("8XXXXXXXXXXXXX", 1, 8)]/State
This line of code works. however, i cannot get it to take the data from the account field.
Path i used to point the the account text box:
/my:CoachingOp/my:SetArea/my:account
Is there a certian type of data it has to be (double, string, interger)?
It seems you have edited your post, but in a previous version of your post I saw that you had the path in quotation marks (i.e. "/my:CoachingOp/my:SetArea/my:account"). It should not be in quotation marks.
I'm 95% sure it's a problem with your path to the my:account field. Could you post a screenshot of your main data source layout (from the taskpane)?
im pretty sure you are right about that
That's not your main data source. Could you change the dropdown there to show me the data source that includes my:account?
But that would have made sense? why would i have done that?
Sorry, skipped the morning coffie earlier
Thank you. Yes, it looks like my:CoachingOp/my:SetArea/my:account is probably the right path. Did you try putting it all together with get-DOM() and everything?
xdXDocument:GetDOM("Systems By SysPrin")/Row[SysPrin = substring(xdXDocument-get-DOM()/my:CoachingOp/my:SetArea/my:account, 1, 8)]/State
my: might not be the correct namespace if you're basing the form off of a pre-made schema. If the above doesn't work, you can right-click account in the taskpane and pick Copy XPath to find the XPath that InfoPath is expecting.
If im looking for the sibling of a note, wouldnt the syntax look more like this:
xdXDocument:GetDOM("Systems By SysPrin")/Root/Row[SysPrin = substring(xdXDocument:get-DOM()/my:CoachingOp/my:SetArea/my:account, 1, 8)]/following-sibling::Systems//Root/Row/State
No, I don't think that would be right. That would be make some sense if Row had a sibling called Systems, but I don't see a node called Systems anywhere in your data source. At the point where your red text starts, the XPath is positioned at a Row node assuming the filter found something. And the desired State node is right under the Row node. Are you still getting that error you mentioned? That seems strange because you said that this one worked, albeit without the full functionality you want of course:
Is it perhaps that your XML data source is not set to "query when the form is opened"?
It is set to query when the form is opened, i reloaded it to doublecheck
and i should have noted that i changed the name of the XML doc to "System" from "Systems by sys prin" to make it easier for me to test my code
correct me if im wrong, but if it displays the State when i enter in the account number manualy, but not when the users enter it in the my:account field, wouldnt that mean that the XML doc is loaded fine because it displayed the State in the first place, and the problem was with the path to the my:account field?