19 Replies Latest reply on May 27, 2009 2:32 PM by Duniagdra

    Trouble getting Scripts to do their thing

    Duniagdra

      I'm having multiple issues here.

       

      1. The Membership Type Group
        1. I have a script in the first checkbox as follows:
          form1.MembershipRenewalAppForm.MembershipTypeGroup.MemberTypechkGroup.chkMST-NRM::initialize - (JavaScript, client)
          if (this.rawValue == true){
               chkMST-RFP.presence = "invisible"
               chkMST-ARC.presence = "invisible"
               chkMST-Corp.presence = "invisible"
          }else {
               chkMST-RFP.presence = "visible"
               chkMST-ARC.presence = "visible"
               chkMST-Corp.presence = "visible"
          }
          
          1. If this checkbox is chosen the three checkboxes beneath should go invisible because they become a non-option item. They don't go invisible.
        2. Once any of the four checkboxes are chosen, a value becomes available in the numberfields to the left of the checkboxes. Here is the Script i'm using in the numberboxes:
           form1.MembershipRenewalAppForm.MembershipTypeGroup.MembershipValueGroup.MT15::initialize - (JavaScript, client)
          if (chkMST-NRM.rawValue == true)
               this.rawValue = 15;
          else
               this.rawValue = 0;
          
          1. I'm noticing now that LiveCycle has this.rawValue = 15; highlighted in pink, so this must be my issue, but I'm not knowledgeble in scripting. I've been copying scripts that are close to what I need and hacking my way through it. I didn't succeed yet. the other three are the same with the only change being -RFP and 20, -ARC and 10, Corp and 100.
      2. The Driver Classes Group
        1. Numberfield DCSub is showing formating applied as $0.00, bot not picking up the adition when checkboxes in DriverClassesGroup are selected. The script used is this:
           form1.#subform[1].DriverClassesGroup.DCSub::calculate - (JavaScript, client)
          // Set the field properties.
          if (DriverClassesGroup.rawValue > 1)
              this.rawValue = chkMST-ARC.rawValue * DriverClassesGroup.rawValue - chkMST-ARC.rawValue;
          else 
              this.rawValue = 0;
          
          1. There are a total of eight checkboxes to be selected, but nothing is happening. I'm thinking this may be due to Problem 1 above.
      3. The Final Total
        1. Numberfield SumBalance is to total up all values. This is the script:
           form1.#subform[1].SumBalance::calculate - (JavaScript, client)
          this.rawValue = MT15.rawValue + MT20.rawValue + MT00.rawValue + DCSub.rawValue;
          
          1. This is not totaling. Again, I'm thinking this is due to Problem 1 above.
      4. In any Case
        1. All these numberboxes dhould at least show a value of $0.00 in that format, so I'm thinking it has to do with my hacking of the script. I just don't know what it is that is incorrect.
      5. The Reset Button
        1. If the user is to select the reset button the MemberID Textbox at the top of the form needs to become Invisible on select. I tried adding this script to it:
           form1.#subform[1].ResetButton1::click - (JavaScript, client)
          xfa.host.resetData();
          MemberID.presence = "invisible"
          
          1. I've added the "MemberID.presence = "invisible"" to the button. I'm guessing this was a wrong approach, but i'm not finding it highlighted in the script box like I do for the four in the Membership Type Group.

       

      I'm attaching both the link to the form and the file itself for anyone who may be generous enough to help in this. I would be greatly appreciative in getting this resolved.

       

      Here is the Link.

       

      Thanks in advance,

      D

        • 1. Re: Trouble getting Scripts to do their thing
          Duniagdra Level 1

          Sorry, I just relized I may need clarification on problem 2.a the script shown.

           

          This line:

          (DriverClassesGroup.rawValue > 1)

          is meant to be if more than one checkbox in DriverClassesGroup is selected, calculate, otherwise the value is $0.00.

          • 2. Re: Trouble getting Scripts to do their thing
            Kevin Cavallo Level 4

            D, there are lots of little problems in here.  Have you made any headway or changes to the form since you last posted it?

            • 3. Re: Trouble getting Scripts to do their thing
              Duniagdra Level 1

              No, not in the least. I've made no headway at all since posting this. Did I really mess up badly?

               

              Thanks for your attention,

              D

              • 4. Re: Trouble getting Scripts to do their thing
                pguerett Level 6

                I looked at your form and have modified it (see the attachment). There are three fundamental problems that you ran into.

                 

                1. The location of the objects that you are addressing in the script relative to the object that is calling the script. If you look at the hierarchy it acts very mush liek a file system with directories in files. If you want to address a file from another directory you must path to it. It is the same for objects in the hierarchy. As a quick shortcut (and to save you from typing long path names) in the script editor place the cursor where you want the expression to go. Now hold down the Ctrl key and move the mouse to the field that you want to address on the canvas. The cursor will change to a V. Once on the field click the mouse and it will put the relative expression into the script editor. Now you can add th emethod or property you want to address. Note that in a few cases you were trying to check the status of a group object. That has no value, it is simply for ease of design.

                 

                2. The event model needs to be understood a little better. You had most of your code on the Initialize event. That event will only fire once when the form is loaded. So any changes the user makes will not even fire the code. On the checkboxes I moved your code to the change event. That means that each time the checkbox changes (on/off) the script will run. On the fields, the code runs on the calculate event. That means the the event will fire each time the form loads and each time a field named in the script changes. So when the user picks a class the subtotal will update with current information.

                 

                3. The logic for checkboxes that make up the classes was flawed. I changed it to add a field to hold the number of checkboxes that were checked. Then I added code to each checkbox to update the field by 1 when it was checked and decrement the counter by 1 when unchecked. This field should be hidden from the user. I left it visible so you can see it and how it works. Because this field is named in the Total calc it will update the total each time you choose a checkbox.

                 

                Paul

                • 5. Re: Trouble getting Scripts to do their thing
                  Duniagdra Level 1

                  Paul, Thanks for your time. I'm just having one problem. The dollar amounts are not changing. If I check off Non Racing Membership the three bellow go invisible, which is great, and it's corresponding textfield is giving a value of $15.00. If I uncheck it the three bellow reappear, which is great, but I'm still not getting the monetary value in the textfields to their left.

                   

                  At the bottom for the classes, the counter works fine, but I'm not seeing the dollar amount being calculated, which I'm ecpecting to be because the textfield it is needing the multiplied value from (MT10) is not changing from $0.00.

                  • 6. Re: Trouble getting Scripts to do their thing
                    pguerett Level 6

                    I didn't add the code for that. I did it on the 1st checkbox to show you how and figured you could add the appropriate code to the others.

                     

                    Paul

                    • 7. Re: Trouble getting Scripts to do their thing
                      Duniagdra Level 1

                      I tried Editing my reply above but it wouldn't let me,Permission denied".

                       

                      Sorry, I found what needed to me changed But I'm realizing that once additional classes are check, I need confirm that MT10 has a value of 10 and if not, I need chkMST-ARC == true only if more than one class is chosen. How would I write that if statement and where would I apply it?

                       

                      Thanks for your attention,

                      D

                      • 8. Re: Trouble getting Scripts to do their thing
                        pguerett Level 6

                        You could add to each of the class checkboxes:

                         

                        chk-MST-ARC.rawValue = 1

                         

                        That will check the checkbox on, this causing the MT10 field to update, or you can simply update the MT10 field directy:

                         

                        MT10.rawValue = 10

                         

                        You shoudln't have to check its value as you are setting it to the same value .....so simply set it rather than checkit

                         

                        Paul

                        • 9. Re: Trouble getting Scripts to do their thing
                          Duniagdra Level 1

                          I tried applying the line as you said to the classes checkboxes i believe you mean. Nothing is calculating now. Here is the script:

                           form1.#subform[1].DriverClassesGroup.SmallTruckGroup.Classes[0]::change - (JavaScript, client)
                          if (this.rawValue == "1"){
                               NoClassesSelected.rawValue = NoClassesSelected.rawValue + 1;
                               chkMST-ARC.rawValue = 1
                          } else {
                               NoClassesSelected.rawValue = NoClassesSelected.rawValue - 1;  
                          }
                          

                          I know that is wrong, you said earlier that I need to specify the "path?" I think.

                          • 10. Re: Trouble getting Scripts to do their thing
                            pguerett Level 6

                            Use the technique I described earlier where you have Designer determine the path. Put your cusror in the script editor wher yo uwant the expression to appear. Then hold the ctrl key down and drag the mouse onto th eobject you want to address. The cursor wil lchange to a V. Then click and the proper expression relative to th eobject that is running the script will appear in the script editor.

                             

                            Paul

                            • 11. Re: Trouble getting Scripts to do their thing
                              Kevin Cavallo Level 4

                              I don't recommend using '-' as part of an object name.  Javascript interprets chkMST-ARC as 'chkMST minus ARC'.  That's why you need to surround those object references with xfa.resolveNode("object") while others don't require it.  It is helpful to use Paul's technique since Designer knows when that's necessary.

                               

                              Also, don't forget the semicolons at the end of your statements:

                              xfa.resolveNode("chkMST-ARC").rawValue = 1;

                              • 12. Re: Trouble getting Scripts to do their thing
                                Duniagdra Level 1

                                Gentelmen thank you, with each bit of help I get from you, I come a little closer to uderstanding Designer better. Yes, I've followed the path technique and found the DCSub and the NoClassesSelected were not calculating. I hacked my way through by comparing what was done in chkMST-NRM and found that I needed something more so before the "=" I typed "." and scrolled through the options privided. Nothing seemed right to me except for setAtribute so I gave that a try. The NoClassesSelected counts the number of classes chosen, but still does not set chkMST-ARC as checked. I'm thinking that instead of "1" I need either "true" or "On", but when I tried that the DCSub was not calculation because chkMST-ARC was not setting. Here is what I have:

                                 form1.#subform[1].DriverClassesGroup.SmallTruckGroup.Classes[0]::change - (JavaScript, client)
                                if (this.rawValue == "1"){
                                     NoClassesSelected.rawValue = NoClassesSelected.rawValue + 1;
                                     xfa.resolveNode("MembershipRenewalAppForm.MembershipTypeGroup.MemberTypechkGroup.chkMST-ARC").setAttribute  = 1;
                                } else {
                                     NoClassesSelected.rawValue = NoClassesSelected.rawValue - 1;  
                                }     
                                
                                

                                Once I manually check chkMST-ARC the form works as it should, but if it's not checked and additional classes are chosen... chkMST-ARC does not set.

                                • 13. Re: Trouble getting Scripts to do their thing
                                  Duniagdra Level 1

                                  I'm just now seeing Kevin's post so let me try adding .rawValue in place of .setAttribute. I'll post my result in a moment.

                                  • 14. Re: Trouble getting Scripts to do their thing
                                    Duniagdra Level 1

                                    Gentlemen, thanks for your help. I am yet another step closer to success.

                                     form1.#subform[1].DriverClassesGroup.SmallTruckGroup.Classes[0]::change - (JavaScript, client)
                                    if (this.rawValue == "1"){
                                         NoClassesSelected.rawValue = NoClassesSelected.rawValue + 1;
                                         xfa.resolveNode("MembershipRenewalAppForm.MembershipTypeGroup.MemberTypechkGroup.chkMST-ARC").rawValue = 1;
                                    } else {
                                         NoClassesSelected.rawValue = NoClassesSelected.rawValue - 1;  
                                    }
                                    

                                    chkMST-ARC is now setting as if checked. However, I'm not seeing MT10 receiving a value once chkMST-ARC is set as checked. Should I add a line to put the value into MT10 just as chkMST-ARC is being set as checked, or once chkMST-ARC is set as shecked, should that trigger the change state and cause chkMST-ARC to put the value 10 to MT10?

                                    • 15. Re: Trouble getting Scripts to do their thing
                                      pguerett Level 6

                                      Just realized that you are setting the checkbox programmatically then the calc event will not fire .....so you can fire it yourself. After you set the checkbox do this command:

                                       

                                      MT10.execCalculate();

                                       

                                      Paul

                                      • 16. Re: Trouble getting Scripts to do their thing
                                        Duniagdra Level 1

                                        OKay, just had time to try out the calculate(). It didn't work. I tried applying it to chkMST-ARC, no go. I tried applying it to MT10, no go. I tried applying it to each of the classes, no go. I also tried using the path technique, still no go. Please help.

                                        • 17. Re: Trouble getting Scripts to do their thing
                                          pguerett Level 6

                                          Sorry you want to click th echeckbox and fire the change event on the checkbox (that is where you should have added the code to update the field). To do that add this code:

                                           

                                          xfa.resolveNode("MembershipRenewalAppForm.MembershipTypeGroup.MemberTypechkGroup.chkMST-AR C").rawValue

                                          = 1;

                                          xfa.resolveNode("MembershipRenewalAppForm.MembershipTypeGroup.MemberTypechkGroup.chkMST-AR C").execEvent("change");

                                           

                                           

                                          Or you can simply update the MT10 field directly.

                                           

                                          Paul

                                          • 18. Re: Trouble getting Scripts to do their thing
                                            Duniagdra Level 1

                                            Excellent! Thanks for all your trouble and time.

                                             

                                            Form works great!

                                            • 19. Re: Trouble getting Scripts to do their thing
                                              Duniagdra Level 1

                                              Sorry, forgot... The reason that I choose not to rely on updating manually is simply because out of more than 350 million people, there's bound to be a few that may apply to our organization and not check off Additional Racing Classes and then submit the incorrect fee with the membership application. This avoids that mistake.

                                               

                                              Thanks again,

                                              D