2 Replies Latest reply on Apr 22, 2013 7:30 AM by s

    How to start a scripted / upgrade import


      Hi All


      A little confused on how to start an import from a previous DB with many TO's and all the same field names, to a newer version of my solution.


      I am able to do it all manually by selecting each TO and selecting matching fields.


      Can I set a $variable with the name/path of the file I wish to import from (Source file) ?


      Also, how do I set next serial value +1 on the last record, when my pk are prefixed with text ie INV0001234 ?




      Regards Michael

        • 1. Re: How to start a scripted / upgrade import

          You have to perform a separate import for each table, but you can do this easily in your script.  I usually set a variable that I call $Path and it is the path of where the file is that you are importing from and you use the variable in your import instead of specifically identifying the file location.  You can control the next serial values by having the import perform the auto calcluation functions.  It is a checkbox you are prompted for when you setup the import script.  It assumes you have the calculation setup already in your database serialized field. 

          1 of 1 people found this helpful
          • 2. Re: How to start a scripted / upgrade import

            Hi Michael,


            As Taylor said, you can capture the filename into a variable, to be used in your import scripts:

            - prompt the user to select a file to insert into a global container field,

            - set $$Path to the last value of getastext(containerfield)

            (I would use a global variable unless all your imports are in the same script.)


            Capturing the next serial value is more tricky, however, because as they use the deployed file, their serial numbers will be much higher than those in your development copy. You don't want the next serial value from the development file, you need it from the deployed file.


            You do NOT want to reset the serial numbers on import if you are using those serial numbers in relationships, and the deployed file has related records.


            Supposedly, you can use GetNextSerialValue(filename ; fieldname), where filename is $$Path, but I have not been able to make that work. Perhaps the syntax is different? The help file says filename must be open - maybe that's my problem.



            Hopefully, someone else will chime in telling us how to make that work, cuz that would be the simplest.


            So how else to get the next serial value from each table in the deployed file? You could use a summary calculation (Max), if your serial number fields are numbers (not text). But it may be slow if you have tens of thousands of records to import.


            You could create a cartesian join on the serial number field in each table, then use the Max function after import and add 1 to that.

            Correction: I used List plus a custom function to get the Max value. (http://www.briandunning.com/cf/753)


            Good luck!



            Steve Moore

            Cumberland, Maine

            1 of 1 people found this helpful