8 Replies Latest reply on Oct 30, 2015 5:05 AM by karimhanafi

    Script not calculating correctly?

    NickLawrence

      Hi all,

       

      I have a slight problem with a part of a script, the part I'm having problems with is as follows:

       

      Round ( Contracts::Agreed charges 07 MSC percentage / Get ( FoundCount ) ; 2 ) for some reason, even though the field that it refers to is populated with a number it returns 0.00, I've checked the field and it is set up as a number, the format for the number is decimal with fixed decimal place of 2 and the amount entered is 0.1 showing as 10%. At first I thought it was because it was 0.1 and the round function was causing it to zero, however I have put 100 in there and still get zero, doesn't matter what number I put in the Contracts::Agreed charges 07 MSC percentage field, I always get 0.00 as the result. However, if I change the script to Round ( 100 / Get ( FoundCount ) ; 2 ) I get the correct result, so it is obviously a problem with it looking at that field.


      Anyone have any ideas why this would be doing this? And how I can fix it?


      Many thanks

       

       

       

      Nick

        • 1. Re: Script not calculating correctly?
          siplus

          What do you get if you take away the Round() ?


          Set Variable [$valueBeforeRounding; Contracts::Agreed charges 07 MSC percentage / Get ( FoundCount )]

          • 2. Re: Script not calculating correctly?
            NickLawrence

            Hi Siplus,

             

            Many thanks for your quick reply,  if I change the script as suggested I still get 0.00

             

            The actual script line is:

             

            Set Variable [$perc; Value: Round ( Contracts::Agreed charges 07 MSC percentage / Get ( FoundCount ) ; 2 )

             

            This might be more helpful than posting only a bit of it earlier.

             

            Many thanks

            • 3. Re: Script not calculating correctly?
              siplus

              You might be on a layout based upon a table that is not connected to Contracts, because apparently

               

              Contracts::Agreed charges 07 MSC percentage


              evaluates to 0

              • 4. Re: Script not calculating correctly?
                coherentkris

                Their is nothing that i could do to produce the result 0.00 with the calculation as stated.

                it only returns 0

                • 5. Re: Script not calculating correctly?
                  NickLawrence

                  Hi siplus,

                   

                  There is definitely a relationship between the 2 tables, I've just double checked, let me give a bit of an overview:

                   

                  The 2 tables are Contracts and Repayment schedule for contract CD, there is a relationship between the 2 based on Contract ID. The field that I am trying to calculate 'Schedule 02 Percentage' is from the Repayment schedule for contract CD table and on this particular layout (based on contracts) in a portal.

                   

                  Originally (I never created the script) was as follows:

                  Set Variable [$perc; Value: Round ( 1 / Get ( FoundCount ) ; 2 )

                   

                  However, this was not calculating what it should be, as it should take the % entered in to Contracts::Agreed charges 07 MSC percentage and divide it by the number of entries that are specified so that we can calculate the amount due.

                   

                  e.g. in Contracts::Agreed charges 07 MSC percentage there is 12% there is a another field called total fees, what happens is we click on enter repayment schedule, it askes how many repayments, we enter 6, it should add 6 repayments, the 12% should be divided giving 2% in each of the Schedule 02 percentage fields in the portal. Then the schedule 03 amount due calculates the percentage of total fees as set in Schedule 02 percentage entering the amount that is due.

                   

                  But at present all I am getting is a zero. Would I need to create a new relationship for this to work?

                   

                  Many thanks

                   

                  Nick

                  • 6. Re: Script not calculating correctly?
                    NickLawrence

                    Hi coherentkris

                     

                    It shows a result of 0.00 as I have the decimal places fixed at 2, if I remove that then it would just display 0 as you have.

                     

                    Regards

                     

                    Nick

                    • 7. Re: Script not calculating correctly?
                      NickLawrence

                      Hi siplus,

                       

                      This is in fact correct, I never actually checked which table it should refer to, and this was where the problem lied, it should have been 'Contract for repayment schedule::Agreed charges 07 MSC percentage' so once I set this it worked perfectly, thanks for all your help.

                       

                      Regards

                       

                       

                       

                      Nick

                      • 8. Re: Script not calculating correctly?
                        karimhanafi

                        Hi Nick,

                         

                        I am not very clear on the context in which the script step runs. It seems that it is the CONTRACT table.

                         

                        If it is the case and your context is the CONTRACT table, the Get ( FoundCount ) will give the number of Contracts found in the current set, but your formula, as I understand it, needs to have the count of REPAYMENT records. My theory is the found set when in the CONTRACT context is large enough so that the result is less than 0.005, This will always be rounded to zero in your formula.

                         

                        The test Siplus suggested will give you a good insight on the problem at hand but you need to change the number formating to General (in Inspector > Data > Data Formating) before doing the test. Right now, you are rounding anyway because of the formating you are using.

                         

                        If this is indeed the problem, we will need to look at how the script is constructed in order to troubleshoot it.

                         

                        Take care.

                         

                        Karim