[X3v12-4GL] In Script editor, how to open a X3 Storage Area folder to reads its filelist names?

SOLVED

Hi,

4GL Development question. Not sure the keyword to find for these.

In 4GL, I know I can just manually put in the hardcode filepath to open through SYSTEME2 raw OS cmd call but it is very annoying to maintain (about 5+ scripts to update) every time the folder is duplicated to test server.

If I want to access to a defined X3 volume, how to [1] call the defined X3 volume in 4GL and then [2] read a list of the file name inside?

Assume the defined X3 volume is YTEST.

Inside the X3 volume folder are just `.txt` files (1.txt, 2.txt, hello.txt). These files are expected to be imported in as an import template file using 4GL directly through its filename (for example, import `1.txt` file to YTESTIMP import template code).

Additional refs for X3 Volume creation:

https://www.sagecity.com/us/sage_x3/b/sageerp_x3_product_support_blog/posts/creating-storage-areas-for-the-masses-quick-guide-to-adding-custom-storage-areas-to-sage-x3

https://www.sagecity.com/us/sage_x3/b/sageerp_x3_product_support_blog/posts/getting-started-with-x3-storage-areas

Additional details I found while googling:

- From Greytrix (the one I am using; Seems like old way?): www.greytrix.com/.../

- From online help: https://online-help.sageerpx3.com/erp/12/staticpost/x3script-keywords-glossary/

Parents
  • +1
    verified answer

    I would recommend you do no use the System's command due to security restrictions in V12. Instead you can use the following subprogram I wrote a while ago, it takes in three parameters, the first is the full path of the X3 Storage area, which can be constructure by making use of the filpath command (in your example filpath('YTEST','','','') will return 'X:\Sage\Some\Location'. I have a hardcoded file extension filter (aka 'txt' included in my SYSTEM call) as I am only looking for txt files, but it can be updated to other functions as well. The return variable ZNBFIC is the number of files in the folder, and the variable ZFILES contains the names of the files in the directory. Hope it helps. Slight smile

    # FIND ALL TXT FILES IN A SPECIFIC FOLDER
    ###########################################################################################
    # PARAMETERS : 
    # ZFOLD - X3 STORAGE LOCATION (EXPRESSED USING filpath COMMAND)
    # ZNBFIC - NUMBER OF FILES FOUND IN THE FOLDER
    # ZFILES - LIST OF NAMES OF TXT FILES IN THE FOLDER
    #
    ###########################################################################################
    Subprog FIND_FILES(ZFOLD, ZNBFIC, ZFILES)
    Value Char ZFOLD
    Variable Integer ZNBFIC
    Variable Char ZFILES()(1..)

    # USE A X3 SYSTEMS CALL TO PERFORM A DIR *.txt ON THE FOLDER PROVIDED IN ZFOLD
    Call SYSTEME2(adxmac(0),"lsadx"-'"'+ZFOLD+'" "txt"',"", ZNBFIC, ZFILES) From ORDSYS

    End

Reply
  • +1
    verified answer

    I would recommend you do no use the System's command due to security restrictions in V12. Instead you can use the following subprogram I wrote a while ago, it takes in three parameters, the first is the full path of the X3 Storage area, which can be constructure by making use of the filpath command (in your example filpath('YTEST','','','') will return 'X:\Sage\Some\Location'. I have a hardcoded file extension filter (aka 'txt' included in my SYSTEM call) as I am only looking for txt files, but it can be updated to other functions as well. The return variable ZNBFIC is the number of files in the folder, and the variable ZFILES contains the names of the files in the directory. Hope it helps. Slight smile

    # FIND ALL TXT FILES IN A SPECIFIC FOLDER
    ###########################################################################################
    # PARAMETERS : 
    # ZFOLD - X3 STORAGE LOCATION (EXPRESSED USING filpath COMMAND)
    # ZNBFIC - NUMBER OF FILES FOUND IN THE FOLDER
    # ZFILES - LIST OF NAMES OF TXT FILES IN THE FOLDER
    #
    ###########################################################################################
    Subprog FIND_FILES(ZFOLD, ZNBFIC, ZFILES)
    Value Char ZFOLD
    Variable Integer ZNBFIC
    Variable Char ZFILES()(1..)

    # USE A X3 SYSTEMS CALL TO PERFORM A DIR *.txt ON THE FOLDER PROVIDED IN ZFOLD
    Call SYSTEME2(adxmac(0),"lsadx"-'"'+ZFOLD+'" "txt"',"", ZNBFIC, ZFILES) From ORDSYS

    End

Children