Calculating Fields based on a value - InfoPath Dev
in

InfoPath Dev

Calculating Fields based on a value

Last post 12-11-2010 12:53 PM by jappiej. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 12-02-2010 05:20 AM

    Calculating Fields based on a value

    Hello Users,

    I got a simple question, but couldn't find the answer here, or my search query wasn't good.
    I'm using Infopath 2007.

    I have a field (field1), when i fill in this field a number for example 5 i want to show a table with 5 fields.
    An other existing field (field2) is a calculating a sum of other fields.
    The 5 fields that in the table are created must do also calculate the field2 / field1

    for the picture:
    field1 value =  5
    field2 value =  100 
    the 5 fields that are created have the value of 20 in each field.

     

    Is that possible ?

     

    Thanks in advance.

  • 12-02-2010 06:52 AM In reply to

    Re: Calculating Fields based on a value

    Hi jappiej and welcome to this forum.

    I think you have to use some code to do that. You can use a repeating table and create rows programatically. If you want  I can give you some help for that.

     

  • 12-02-2010 07:10 AM In reply to

    Re: Calculating Fields based on a value

    You can also use qRules to do this.  Just use the Insert command to insert 5 rows, and then use an ordinary rule or default value to set your field to the value of the formula field2 div field1.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-02-2010 10:47 AM In reply to

    Re: Calculating Fields based on a value

    thanks, thought already it would be some sort of code....but don't know exactly where to start.

    if you want to help me i would appreciate it

     

    @Jimmy, thnx for the reply, would try it first with some code

  • 12-02-2010 01:22 PM In reply to

    Re: Calculating Fields based on a value

    Ok here we go. First of all you have to set you security level, so go on tools, form options, security and trust, and select "full trust", you have to select one certifcate to sign your code, if you don't have one office can create one for you. After that on programming select C#.

    Click Ok to close this window. After that you have to set an event handler on your field1 to create your rows right click on the field, programming and select change event, it will open a programming interface.

    here you have to put some code:

    XPathNavigator Root= this.MainDataSource.CreateNavigator();
                //delete all rows of repeating table
                try
                {
                   Root.SelectSingleNode("/my:myFields/my:RepeatingTable/my:MyTable",this.NamespaceManager).DeleteRange(Root.SelectSingleNode("/my:myFields/my:RepeatingTable/my:MyTable[last()]",this.NamespaceManager));
                }
                catch { }
                int NumOfRow=0;
                //take the num of rows to create
                int.TryParse(e.Site.Value, out NumOfRow);
                for (int i = 1; i <= NumOfRow; i++)
                {
                    XPathNavigator Clonenode = Root.SelectSingleNode("/my:myFields/my:ReferenceGroup/my:RepeatingTable/my:MyTable", this.NamespaceManager).Clone();
                   
                    //add your code to divide here

                    Root.SelectSingleNode("/my:myFields/my:RepeatingTable", this.NamespaceManager).AppendChild(Clonenode);

                }

    You have to use your own xpath. I attach my own test form if it can help.

     

  • 12-02-2010 11:07 PM In reply to

    Re: Calculating Fields based on a value

    Thanks, i'm gonna try it and will let you know if it works for me :)

    BTW, when i open youre template it also asked for the Template1.csproj :)

  • 12-03-2010 12:11 AM In reply to

    Re: Calculating Fields based on a value

    Security level = Full Trust!? Please don't do that! That is not a best practice. 95% of all forms do not need to be Full Trust and it complicates and adds cost to your deployment (because you have to sign the form or use an MSI to install it).

    You don't need full trust to solve this problem in code. Not sure why Potemkine is asking you to do that.

    But seriously, why waste time on code that you'll have to maintain in all of your templates. Just use qRules free trial and it will take you 15-20 minutes. It's really simple - that's why we created it - to help answer the most common needs of users in the forum. It also helps us pay for the forum and it's really cheap - did I say free trial?

     

    Patrick Halstead
    Project Manager at Qdabra
  • 12-03-2010 06:56 AM In reply to

    Re: Calculating Fields based on a value

    Hi,

    jappiej:
    BTW, when i open youre template it also asked for the Template1.csproj

    Yes, it's normal I just put the template to show you my xml structure.

    Patrick it's certain that the it's better to have the lowest security level on a form and Qrules can certainly help you to go on that way. But the possibility to add code on a form is also a really good feature I just help him on this way.

  • 12-03-2010 09:06 AM In reply to

    Re: Calculating Fields based on a value

    Looking at the code sample provided, I see nothing that would require full trust. This code should run under domain trust. Of course, if this is for a browser form, the form has to be admin deployed....

    Hilary Stoupa

  • 12-03-2010 11:25 AM In reply to

    Re: Calculating Fields based on a value

    Hi Hilary yes it should run on domain trust and I should have said that I just had the reflex to set to "Full trust" when I use code.

  • 12-04-2010 08:05 PM In reply to

    Re: Calculating Fields based on a value

    Great to have your posts on this forum Potemkine. You always open my eyes a little and I am very thankful.

    Patrick Halstead
    Project Manager at Qdabra
  • 12-11-2010 12:53 PM In reply to

    Re: Calculating Fields based on a value

    thanks all for the help, but at the end it wasn't necessary.

Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.