5 Replies Latest reply on Feb 18, 2013 3:01 PM by nickchapin

    Call a script to calculate a field value

    ericjlawson

      Hi,

       

      I want to set a table value to be a CHAR (2) value representing the invoicing year (eg. "13"). Its not based strictly on calender year so I need to use a script.

       

      Can I call this script from the Calculated Value dialog for Auto Enter of a table field value. If yes and if this is part of a 1 row table defining certain parameters for this application / database, will it execute each day the application is started up, thereby ensuring the correct value isstored for subsequent retrieval when generating invoice codes?

       

      Or should I be defining a script to run at startup time for each session and loading this value into a global variable?

       

      Thanks

      Eric

        • 1. Re: Call a script to calculate a field value
          ariley

          Hi Eric,

           

          Can you please tell us what you are trying to achieve in laymen's terms?

           

          You canot call a script nrmally from a calcuation. There's a plug-in for that if I remember correctly, but it might not be updated for the latest FM. You can trigger a script from a field on a layout. Or you can automate the whole action by scripting it and setting the field with the year value you want.

           

          So, tell us, what you are aiming for so we can help better.

          1 of 1 people found this helpful
          • 2. Re: Call a script to calculate a field value
            nickchapin

            Hi Eric:

             

            You can't actually call a script from a calculation (without using calls to external plug-ins). Auto-enter calculations need something to trigger the calc to occur; usually this is record creation, but the calc can be popped other ways. For your solution it sounds like you may just want to go the easy route of calling a startup script.

             

            Since you describe your table as always having one row, have you considered using global variables to hold your application parameters rather than storing it in a table with it's associated overhead and management?

            • 3. Re: Call a script to calculate a field value
              beverly

              You can script a Set Field and specify the calculation that will be used to enter data into the field. This script is not triggered automatically, but if you have FMS, then you can "schedule" it to run daily. I guess the usage of this data could also be such that it's a calculated field, rather than global. It may depend upon where the data is used and when. And there is always a custom function to create the value, which is then called by other fields and script steps as needed.

               

              Beverly

              1 of 1 people found this helpful
              • 4. Re: Call a script to calculate a field value
                ericjlawson

                Thanks Nick. I have defined a global variable for this and have set the script to trigger on the layout I have nominated as the one to display on startup.

                 

                Unfortunately the script is not firing when it should on first entry but I expect I can sort that out (unless there is something special about this first layout display).

                • 5. Re: Call a script to calculate a field value
                  nickchapin

                  Your welcome!

                   

                  On triggering: You might want to check what event you're looking at when you trigger the script on your layout; I think you would want "On Layout Enter" here.

                   

                  BTW: Some enterprising individual (I think is was Mislov Kos) came up with a nice graphic on script triggers you might find helpful; I've included it here.