Manipulating Default Values - InfoPath Dev
in

InfoPath Dev

Manipulating Default Values

Last post 06-16-2009 01:19 PM by Hilary Stoupa. 15 replies.
Page 1 of 2 (16 items) 1 2 Next >
Sort Posts: Previous Next
  • 04-27-2009 05:52 AM

    Manipulating Default Values

    Hello there,

     I've asked a similar question before. However, I didn't think I explained it well and as a result had no response.  I really hope I explain it better this time :)

     As you know, if you have a repeating table/section, you can go to Tools-Default Values and add more nodes to the data source. If two nodes are added it will mean when the form is previewed there will automatically be two repeating tables on display. 

    Lets say I want to automatically populate a particular field (called fld_ID) within each repeating table , I can go into Default Values and select fld_ID and add a value to it and repeat this on the next node with a different value.  If I add 1 to the first nodes-fld_ID and 2 to the second nodes-fld_ID, then preview the form, I'll see the two repeating tables. The first table's fld_ID will have 1 and the second will have 2 populated.

    What I'm trying to do is dynamically add the default values when a value from a drop down list is selected.  Depending on the value on the drop down list, different values in the nodes fields will change.  I've tried to do this by entering values using such techneques as the filter from within the Defualt Values and adding a formula to each node. However, doing this on Node 1 -fld_ID changes all fld_IDs in all nodes.

     Is there a way to do this so that the drop down box will populate different values to the fields on each repeating table depending on the value in the drop down?

     I'd appreciata any help or advice with this.  Even if you think it's not possible, please tell me this as well as this would help.

    Many thanks

    ____________________________________

    Take a deep breath phsssssssssss
  • 05-14-2009 06:20 PM In reply to

    Re: Manipulating Default Values

    Hi -- what about using rules to populate the fields? This would work if the drop down was bound to a field in the same group as the field that you want to change the value on. Otherwise, take a look at this InfoPath Team blog post on conditional defaults... it may help. I've used the second method mentioned quite frequently, and while it seems really complex when you first read through it, it actually isn't too bad once you've given it a try....

    Hilary Stoupa

  • 05-22-2009 02:06 AM In reply to

    Re: Manipulating Default Values

    Hi Hilary, Thanks for replying.  Please bare with me :)

    I followed the link and attempted the second approach (see what I did below just to test.)

    I went to default values on the tools menu and added one extra node (so there was two).  I went into that node and in one of the fields (field_ID) I added the formula.  However, this also added the same formula to the second node which I dont want.  This is because there are 7 nodes I need in total (so the user will see 7 sections), and each nodes field_ID's value will be different depending on 5 possible values from the drop-down list.  The technique you suggested changes all the field_IDs to the same value as they now all have the same formula.  It would have worked if each node field_ID could have had its own formula. 

    For example, if I create 7 repeating sections of the same database table, and 1 is selected from a drop down list at the top of the form, then the first field_ID of the first repeating section should say 1, the second field_ID of the second repeating section should say 2 and the next one '3' and son on.  If 2 is selected from the drop-down, the first node will say 8 and the second will say 9 etc.

    The nodes only seems to have different values if I type in a value and not a forumla in each node.  If I type the value 1 to the first node and 2 to the second node field_ID, and view the form, I'll get different values on each nodes field_ID.

     I don't know if what I'm suggesting is possible.  Really hope you can help me a little more.  If you don't think it's possible, I'd be happy with your opinion as well :)


    concat(substring("success", 1, @ProjectTypeFK[. = 1] * string-length("success")), substring("undefined", 1, (not(@ProjectTypeFK[. = 1])) * string-length("undefined")))

    Notes: @ProjectTypeFK is the dropdown list.  if one is picked, the nodes field_ID (where the formula has been put) will say success, if not, it will say undefiend

     

    ____________________________________

    Take a deep breath phsssssssssss
  • 05-22-2009 07:40 AM In reply to

    Re: Manipulating Default Values

    If you need a row counter -- that is, an id for each row that increments by one, check out this sample form. I'm still having a really hard time understanding what you are trying to do, I'm afraid...perhaps you could attach a sample form to your next post (under the Options tab when you reply) or some screen shots.... 

    For your formula -- make sure you use the 'insert field or group' to pick the @ProjectTypeFK field and add the filter. I think you at the very least need to add parenthesis around the first boolean in the first substring (I'm assuming you posted the formula because it is not working correctly?). So:

    concat(substring("success", 1, (@ProjectTypeFK[. = 1]) * string-length("success")), substring("undefined", 1, (not(@ProjectTypeFK[. = 1])) * string-length("undefined")))

    Hilary Stoupa

  • 05-25-2009 05:32 AM In reply to

    Hi Hilary,

     The insert fields where used, the suggestion is not quite what I was looking for however.

    I've attached some screenshots to elaborate what I mean.  The drop down list adds values to the Main parent table (msdbProjects) and depending on that value, I'd like the node fields populated appropriately.  As you can see from screenshots 3 - 4, if the drop down list value is [Choice One] then there are specific values that enter the three tables Field_IDs (these ID's being the same field but a three rows are created in the database).

    If I go to [Default Values] and put the formula you suggested in one of the nodes field_Id's, then the formula is carried to all of the nodes and this would mean that each of the repeating section controls (Field_ID)  would have the same value.

    I hope this help explain and thanks for your patience on this:)

     

    Paul


    ____________________________________

    Take a deep breath phsssssssssss
  • 05-25-2009 04:19 PM In reply to

    Hi--

    Check out the attached sample form. Right click the link in the header of this post and save the file locally. Then open in design mode (right click and select design) and preview the form. Selecting values from the drop down at the top will populate values in the repeating table below. The default on the field in the table is:

    concat(substring(concat(../../../my:field1, " ", count(../preceding-sibling::my:group2/my:field2) + 1), 1, (../../../my:field1 != "") * string-length(concat(../../../my:field1, " ", count(../preceding-sibling::my:group2/my:field2) + 1))), "")

    Basically, if nothing is selected in the drop down, nothing displays in the fields in the repeating table. But once a selection has been made, you get the value of that field, a space, and an incrementing number....

    Hilary Stoupa

  • 05-26-2009 02:29 AM In reply to

    Re: Manipulating Default Values

    This looks like it may work, and if it does I'll buy you a big bunch of flowers one day :)

     I take it this technique can be used for repeating sections; 7 of them, as shown in the screenshots?

    I'll have a look at this at some point today and get back to you... Thanks again Hilary

     

    Paul

    ____________________________________

    Take a deep breath phsssssssssss
  • 05-26-2009 02:57 AM In reply to

    Re: Manipulating Default Values

    Hi Hilary,

    I've had a look at the form, and this techniqe is very close to what I'm looking for.  There is, however, one problem.  The technique would have to be more conditional.  For example, if 'first choice' is selected from the drop down, the values in 'field2' would be from 1-7, if the 'second choice' was selected from the drop down, the values would be from 8-15, Third choice 16-23 etc.

    There are 4 choices in the actual drop down list I'll be using and there will be 7 repeating sections (7 nodes).  The values that populate "field2" represent project stages. In the real forms they are keys that reference a lookup table that has the descriptions of the project stages and each project description is different with each of the 4 choices in the drop down list (choice one has a different set of descriptions, hence the different keys)

    I'm thinking I may need code for this... perhaps you know of some articles that can specifically help me with this as I've not coded with Infopath yet.

     Many thanks

    ____________________________________

    Take a deep breath phsssssssssss
  • 05-26-2009 03:56 PM In reply to

    Do you know what the values will be for those 4 choices in the drop downs? Are those values pretty static? Here's one more try with a default value set up (sample in header again).

    If you end up needing to add code to your form, I'd suggest making sure you set the programming language to C# first -- you'll find more samples. Tools / Form Options / Programming. This blog post by S.Y.M Wong-a-Ton may help you get started....

    Hilary Stoupa

  • 05-27-2009 02:39 AM In reply to

    Hilary, you're a GEM! This looks like the resolution I was looking for.

    I've spent a bit of time with it and am having difficulty with the syntax because I'm using fields from a database.  I've tried this


    substring(concat("1", count(/preceding-sibling::msdbMilestone1/@MilestoneDetaiID1) + 1), 1, (../../@ProjectTypeFK = 1) * string-length(concat("1", count(/preceding-sibling::msdbMilestone1/@MilestoneDetaiID1) + 1)))

     I've taken some of the elements and played about with it but no joy!  I've asked for quite a lot from you. Perhaps you can help me just a little more.

    I've attached a screen shot of the default values that I'd be using, maybe you could help me with the syntax?

    Many thanks again :)
    Paul

     


    ____________________________________

    Take a deep breath phsssssssssss
  • 05-28-2009 07:37 AM In reply to

    Re: Manipulating Default Values

    Hi, Paul:

    Is the error on the count of the preceding sibling section? Or the part you've highlighted in blue?

    Hilary Stoupa

  • 05-28-2009 07:48 AM In reply to

    Re: Manipulating Default Values

    Hi Hilary, unfortunately I'm away on holiday tomorrow for a week so I'll have to postpone this thread until then.

    I've managed to get rid of the error with the code below but the controls all give me '11' when I select 1 drom the drop-down (I've only tested the code with the first part of the code below).  rather than the first field giving me 1 and the second field giving me 2 etc.  I've tried numerous attempts but all the fields in each section end up being populated with 11.

    Hope that helps you help me :)

    Thanks,
    Paul

    substring(concat("1", count(../preceding-sibling::*/@MilestoneDetaiID1) + 1), 1, (../../@ProjectTypeFK = 1) * string-length(concat("1", count(../preceding-sibling::*/@MilestoneDetaiID1) + 1)))

    ____________________________________

    Take a deep breath phsssssssssss
  • 06-06-2009 12:06 AM In reply to

    Re: Manipulating Default Values

    I would recommend you take the formula apart a bit. Start with making sure you are getting your incrementing number correctly. So try just (../preceding-sibling::*/@MilestoneDetaiID1) and see what you get. It sounds like right now you are getting '0', which explains one of the '1's in your '11'.

    What field in your data source is this default being set on?

    Hilary Stoupa

  • 06-11-2009 06:22 AM In reply to

    Re: Manipulating Default Values

    Hi Hilary,

    I'm back from holiday.  I'll work on your suggestion on Monday (you know what it's like when you come back to work to find 800 emails lol)

    Thanks

     

     

    ____________________________________

    Take a deep breath phsssssssssss
  • 06-16-2009 07:30 AM In reply to

    Re: Manipulating Default Values

    Hi Hilary,

    I tried your suggestion and nothing happened.  there's no condition in it.  But when I type a one into the first node field, nothing happens to the others. I've tried playing about with it but to no avial.  it's weird cause I've tried to copy your technique to the t but not getting the same results.  Looks like I'm loosing the battle on this one.  Maybe I'll suprise myself.

    the field that has the formula is @MilestoneDetaiID1 which is the field that will be populated with the incremental value.

    Thanks again.

    Paul

    ____________________________________

    Take a deep breath phsssssssssss
Page 1 of 2 (16 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.