Sage 100

 View Only
  • 1.  Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-01-2024 16:27

    A customer asks if there is a way that they could use VI to read a folder and import all the files in the folder to Sales Order. After the file is imported it would get moved to an archive folder.

    Something like: 

    c:\incoming\orders\

    salesorder1.csv

    salesorder2.csv

    salesorder3.csv

    I'm thinking that it should be possible to do this with a batch file that use a command line to run a VI job. 

    Has anyone tried this and found an easier/better way to import a series of files in a folder? 



    ------------------------------
    Wayne Schulz
    wayne@s-consult.com
    Schulz Consulting
    (860) 516-8990
    Moodus, CT
    ------------------------------


  • 2.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-01-2024 16:33

    I've done this with a VBScript.  Basically, loop through the CSV files in the folder, consolidate them into an AllOrders.CSV file, move / rename the consolidated files as their contents are being copied into the import file (avoiding re-processing in the future), then run the VI job (against the AllOrders.CSV file).



    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 3.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-01-2024 16:36

    That's what I'm thinking too ---- I just tried this with AI and ChatGPT provided this -  

    @echo off
     
    REM Set the folder paths
    set source_folder=C:\INCOMING\ORDERS
    set archive_folder=C:\ARCHIVE
    set output_file=%source_folder%\ORDERS.CSV
     
    REM Check if the source folder is empty (excluding ORDERS.CSV)
    dir /b /a-d "%source_folder%" | findstr /v /i "ORDERS.CSV" >nul
    if %errorlevel% neq 0 (
        echo No files to concatenate. Exiting...
        exit /b
    )
     
    REM Delete the existing ORDERS.CSV if it exists (optional)
    if exist "%output_file%" del "%output_file%"
     
    REM Concatenate all files except ORDERS.CSV into ORDERS.CSV
    (for %%f in ("%source_folder%\*.*") do (
        if /i not "%%~nxf"=="ORDERS.CSV" type "%%f"
    )) > "%output_file%"
     
    REM Check if concatenation was successful
    if errorlevel 1 (
        echo Error during file concatenation. Exiting...
        exit /b
    )
     
    REM Move the original files (excluding ORDERS.CSV) to the archive folder
    for %%f in ("%source_folder%\*.*") do (
        if /i not "%%~nxf"=="ORDERS.CSV" move "%%f" "%archive_folder%\"
    )
     
    REM Check if the move was successful
    if errorlevel 1 (
        echo Error moving files to archive. Exiting...
        exit /b
    )
     
    echo Files successfully concatenated and moved to archive.
     
    REM End script
    exit /b



    ------------------------------
    Wayne Schulz
    wayne@s-consult.com
    Schulz Consulting
    (860) 516-8990
    Moodus, CT
    ------------------------------



  • 4.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-01-2024 16:38

    AI is a wonderful thing. 

     

     

     

    David Overholt

    DWD Technology Group, Inc.

    9921 Dupont Circle Drive West, Suite 300 | Fort Wayne, IN 46825

    260.423.2414 main

    260.399.8655 Direct

    800.232.8913 toll free

    sagesupport@dwdtechgroup.com

    www.dwdtechgroup.com

     

    A black background with white text  Description automatically generated

     






  • 5.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-01-2024 16:48

    You absolutely do not want to delete the import file if it exists... in case the VI job fails for some reason... and you want to rename each file as it is being consolidated (in case new files are inserted while the batch is being run, where the MOVE might catch a file not consolidated in the TYPE step).

    I used VBScript for everything... interesting strategy to use DOS commands, and you can't beat the development time!



    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 6.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-01-2024 18:49

    @Wayne Schulz your example is a BAT file not a VB script.



    ------------------------------
    Doug Higgs
    Midwest Commerce Solutions, Inc
    (312) 315-0960
    Chauffeur, Chef, and Personal Assistant to Sprinkles
    ------------------------------



  • 7.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-02-2024 19:51

    Another option is to use a bat file and instead of concatenating the input files, move each input file, one at a time to the "import" folder then rename the file and execute the VI import.  Loop through until all of the files in the orders folder have been moved and imported.



    ------------------------------
    Doug Higgs
    Midwest Commerce Solutions, Inc
    (312) 315-0960
    Chauffeur, Chef, and Personal Assistant to Sprinkles
    ------------------------------



  • 8.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-02-2024 11:36

    Wayne - Like with all generative AI models, obviously verification of the result and likely adjustment is required and in this case the Chat GPT answer is more intriguing than anything else. For coding purposes, I like the Claude AI over Chat GPT as it generally provides better results I've noticed.

    I've done this type of project several times. The way Kevin described using VBScript is an xlnt plan that gives you a lot of flexibility. Now, if they wanted to run separate V/I imports for each CSV that is being processed in the folder read loop, that can be done. This would be needed if say the 1st import was into S/O Entry but the 2nd was into something else. Also instead of the BAT file, I suggest some simple perform logic at end of each VI job that moves and renames the import file to the archive folder. The renamed file would include the current date and time.



    ------------------------------
    Alnoor Cassim
    Accounting Systems, Inc. (ASI)
    ------------------------------



  • 9.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-02-2024 16:10

    Thanks everyone for the feedback - it's very helpful.



    ------------------------------
    Wayne Schulz
    wayne@s-consult.com
    Schulz Consulting
    (860) 516-8990
    Moodus, CT
    ------------------------------



  • 10.  RE: Automate a VI import to Sales Order to read and import any files in a folder

    Posted 10-02-2024 19:43

    As a follow up to @Alnoor Cassim comment on perform logic, following is what I have used in the past.  I don't think much has changed.

    !batch file created to delete Timeslips import file after importing to GL journal entry
    !Created by Jeff Schwenk  11/01/07 with assistance from SageTalk post
    !http://support.sagesoftwareonline.com/besttalk/messageview.cfm?catid=59&threadid=28010&FTVAR_MSGDBTABLE=
    !1. created a folder "pl" in the MAS90/VI folder
    !2. copied the text above into a notepad file, saved with the name "rename.pl" in the VI\pl folder (didn't make any changes to the text)
    !3. created a simple job, tested to be sure it works without the pl
    !4. on the configuration tab, selected perform
    !5. selected perform type "completion" and changed the command to ..\VI\pl\rename.pl
    !and assistance from PVXlanguage.pdf file
    !6. Modified 2/14/09 to move imported file to archive folder and rename by appending system date and time to file name.

    !erase "..\MAS_BLS\TGBLS\glxfer.old"

    !rename "..\MAS_BLS\TGBLS\glxfer.dat" to "..\MAS_BLS\TGBLS\glxfer.old"

    rename "..\MAS_BLS\TGBLS\glxfer.dat" to "..\MAS_BLS\TGBLS\ARCHIVE\glxfer"+DTE(0:"%Ys%Mz%Dz%Hz%mz%sz")+".dat"



    ------------------------------
    Jeff Schwenk
    Owner
    Bottomline Software, Inc.
    Waynesboro VA
    (540) 221-4444
    ------------------------------