1 2 Previous Next 20 Replies Latest reply on Sep 26, 2016 2:57 AM by Stigge

    Script with a bug.. Need help..

    Stigge

      Hi all

       

      Am getting a bit stuck on one of my scripts..  Everything works exept one of my searches doesnt see the different between 2 texts fields even when there is differences.

       

      The whole script:

       

       

       

      Error (Added some XXXX on the line since there is name and phone nr on it..):

      $Service = "3875 - 3 - Other - Trafikkostnad - 070-636XXXX - XXXXXXX-Lei XXXX - 2016-09"

      Collection::Service = "3875 - 1 - Other - Trafikkostnad - 070-636XXXX - XXXXXXX-Lei (Lei-XXXXXXX) XXXX - 2016-09"

       

      From line: 47 is when things get wrong.

      On line 55 its suppose to check if the $Service and Collection::Service is exacly the same text and if it is then summerize the total amount.. if its not, just ignore.

       

      Can anyone see where the problem is located ? :/

       

      And i know the code isnt perfect written. but it normally works =) so please dont judge me on it =)

        • 1. Re: Script with a bug.. Need help..
          coherentkris

          Line 55 does what you think it does...if the contents of Collection Intra::Text via variable $Service is an exact match with the contents of Collection::Service then line 56 executes. If not then line 57 executes.

          What you should ask yourself is what do you want to happen when the find at line 54 executes and finds no records?

          • 2. Re: Script with a bug.. Need help..
            BruceRobertson

            A very confusing reply. 

            If line 55 is true then line 56 executes.

            If not; then line 56 executes.

            What?

            • 3. Re: Script with a bug.. Need help..
              David Moyer

              Hi,

              are you using Script Debugger and Data Viewer?  I noticed that after line 54, you don't verify that any records are found.

              • 4. Re: Script with a bug.. Need help..
                dtcgnet

                Under certain conditions (when $Service is the same as Collection::Service), then you set a variable called $Summa. The value of $Summa will remain until it is cleared or until it is set to something else.

                 

                So in line 65, you set Collection Intra::Amount in DC to $Summa. After that, you do NOT clear $Summa.

                 

                So the script then proceeds on to the next record in Collection Intra, and goes back to the top of the loop. If $Service is NOT exactly the same as Collection::Service, then $Summa is not touched, so it remains exactly the same as it was for the previous record. When you set Collection Intra::Amount to $Summa...my guess is you're setting it to the wrong value (the one from the previous record). If the next record isn't exact, you again re-use the same $Summa from a few records previous. Every record will be set to the same amount until $Summa is finally changed.

                 

                After line 64, wrap line 65 in an If statement, something like:

                 

                If ( not IsEmpty ( $Summa )

                Set Field [ Collection Intra::Amount in DC ; $Summa ]

                Set Variable [ $Summa ]

                End If

                 

                If $Summa IS empty, what would you want to do to Collection Intra::Amount in DC? Should it be set to zero, or to something else, or should it be left as is? (In the steps I outlined above, it would be left without change if $Summa is empty.

                • 5. Re: Script with a bug.. Need help..
                  dtcgnet

                  In line 8, you Show All Records from the Collection table. You then loop through and clear out Collection::Count for every single record, one at a time.

                   

                  You then find some records, and for those records, you loop through and set Collection::Count to something for those records. That means that the records NOT in the found set are all empty for Collection::Count.

                   

                  My point is...don't show all records and loop through all of them setting Collection::Count to empty. A lot of them are probably ALREADY empty. Instead of Show All Records, use:

                   

                  Enter Find Mode

                  Set Field [ Collection::Count ; * ]

                  Perform Find

                  If [ Get ( FoundCount ) > 0 ]

                  Go to Record/Request/Page [ First ]

                  Your Loop here that is currently lines 10-13

                  End If

                   

                  It'll speed up your script considerably, I'm guessing.

                  • 6. Re: Script with a bug.. Need help..
                    Stigge

                    Guys.

                     

                    Thanks for all replyes.

                     

                    As i stated in my question, my problem is that even if $Service = "3875 - 3 - Other - Trafikkostnad - 070-636XXXX - XXXXXXX-Lei XXXX - 2016-09"

                    it still counts the $Summa when Collection::Service = "3875 - 1 - Other - Trafikkostnad - 070-636XXXX - XXXXXXX-Lei (Lei-XXXXXXX) XXXX - 2016-09".

                    Even though its a big different. Rest of the code acculy works. just that tiny part that doesnt. Am guessing its becouse the text is almost simular. but the Exact code should compare the whole text, shouldnt it ? :/

                     

                     

                    Am sure there is alot in rest of the code that needs improvement, but thats for next step =) need to get it accurate first. =)

                    • 7. Re: Script with a bug.. Need help..
                      Stigge

                      To explain a bit further what and why. =)

                       

                      I have made a software that helps me with my Pre-invoicing at my company. This file is one of the departments.

                      I have a Collection table that lists ALL services availible and used.

                      In this part i need to export all services bound to this department named "3875". exported to a excel sheet to it can be imported in to our SAP system and then becomes an invoice.

                      I have alot of standard services that everything works perfect with.. but some i start by naming "Other" and thats all "special" items thats not normally there.

                       

                      In this case i have phone costs for a user in this department. if looked at other places its different quarters. for some reason the input is a bit different input on.. but thats fine. it should be able to handle that, small differenses in the text. thats why i use the "Exact" code. but for some reason it doesnt work properly.. the texts are obviusly differently, but calculates in my script as the same.. so i end up charging them double for this service and errors like that i cant have :/

                      • 8. Re: Script with a bug.. Need help..
                        BruceRobertson

                        A problem with the script was described to you.

                        Did you fix it?

                        • 9. Re: Script with a bug.. Need help..
                          Stigge

                          Hi.. am not. only using the Pro version. :/

                          • 10. Re: Script with a bug.. Need help..
                            Stigge

                            No i havent. all reply i got for my question is that it should work as intended, but its not :/

                            I might have missunderstood some reply. =)

                            • 11. Re: Script with a bug.. Need help..
                              David Moyer

                              try placing a temporary Pause step after the Perform Find - then you can see what your find produces.

                              • 12. Re: Script with a bug.. Need help..
                                dtcgnet

                                The problem is that you never clear the value of $Summa. I've outlined the solution in my earlier post.

                                • 13. Re: Script with a bug.. Need help..
                                  Stigge

                                  I have clear the value of $Summa. same resault anyway..

                                   

                                  the problem is that it ignores my If statement Exact(). i want the exact to compare the WHOLE text of the variable. but it doesnt :/

                                   

                                  If you look at my 2 examples of the text. they are clearly differently. but still counts as the same and adds the sum of both of them. when it shouldnt.

                                  • 14. Re: Script with a bug.. Need help..
                                    Stigge

                                    I have done that.. And it sepparates all services and summarize them correctly.. exept my example above. :/

                                    In the example the texts are simular, but not the same. the IF statement on line 55 should compare it and see thats its not the same, but it doesnt :/

                                    1 2 Previous Next