Script to select file

I am looking to write a VB Script which:


1) opens a browse file window
2) allows the user to select a file
3) writes the FILENAME that the user chooses to a a UDF in Item Maintenance.

 

Has anyone done this? I'm sure it must be possible!

  • Nevermind- I got it.

     

    Dim objShell
    Dim strFileName
    Dim strFilePath
    Dim objFile
    Set objShell = CreateObject("Shell.Application")
    Set objFile = objShell.BrowseForFolder(0, "Choose a file:", &H4000, "C:\PDFs")
    strFileName = objFile.Title
    strFilePath = objFile.self.Path
    MsgBox "Just the file name: " & strFileName & vbcrlf & "The full path: " & strFilePath 
    Set objFileName = Nothing
    Set objFilePath = Nothing
    Set objShell = Nothing
    retVal= oBusObj.SetValue("UDF_SPEC$", strFileName)

  • Here is what I came up with. It gives you a file dialog instead of a folder dialog. I don't have MAS 200, so I have only tested that it works with MAS 90.

     

    message = "Select file"
    If MAS_SCR_CS Then
        'MAS 200
        oScript.Execute("CALL " & oSession.Wdx & "+""SYZFIL;LOCAL_GET_FILE_BOX_READ"",FileName$," & _
                        oSession.PathCSRoot & ",""" & message & """,$$,$$")
    Else
        'MAS 90
        oScript.Execute("GET_FILE_BOX READ FileName$,$$,""" & message & """")  
    End If
    fileName = oScript.Evaluate("FileName$")
    If fileName <> "0" Then
        retVal = oBusObj.SetValue("UDF_FILE_NAME$", fileName)
    End If

     

  • I'm not getting an error message when clicking the button to run the script; however, the file name UDF is not populated.

     

    I click the button, browse to the folder and select the file, and click OK, but nothing is written to the UDF.

     

    Any ideas as to what is wrong with my script?

     

    dim fileName
    message = "Select file"
    If MAS_SCR_CS Then
        'MAS 200
        oScript.Execute("CALL " & oSession.Wdx & "+""SYZFIL;LOCAL_GET_FILE_BOX_READ"",FileName$," & _
                        oSession.PathCSRoot & ",""" & message & """,$$,$$")
    Else
        'MAS 90
        oScript.Execute("GET_FILE_BOX READ FileName$,$$,""" & message & """") 
    End If
    fileName = oScript.Evaluate("FileName$")
    If fileName <> "0" Then
        retVal = oBusObj.SetValue("AR_Customer_bus_UDF_SELECT_FILE$", fileName)
    End If

  • you are trying to use the button script variable as the column name for oBusObj.

     

    So instead of:

     

        retVal = oBusObj.SetValue("AR_Customer_bus_UDF_SELECT_FILE$", fileName)

     

    you either need

     

        retVal = oBusObj.SetValue("UDF_SELECT_FILE$", fileName)

     

    or

     

        AR_Customer_bus_UDF_SELECT_FILE$ = fileName

     

    The first option requires less configuration. If you go with the second option, you have to setup the variable and check the return box when defining the button in customizer.

  • Makes sense. I will try that.

    Thanks
  • I tried the following script, and it's still not erroring out or populating the UDF.

     

    dim fileName

    message = "Select file"

    If MAS_SCR_CS Then

        'MAS 200

        oScript.Execute("CALL " & oSession.Wdx & "+""SYZFIL;LOCAL_GET_FILE_BOX_READ"",FileName$," & _

                        oSession.PathCSRoot & ",""" & message & """,$$,$$")

    Else

        'MAS 90

        oScript.Execute("GET_FILE_BOX READ FileName$,$$,""" & message & """") 

    End If

    fileName = oScript.Evaluate("FileName$")

    If fileName <> "0" Then

        retVal = oBusObj.SetValue("UDF_SELECT_FILE$", fileName)

     

    End If

     

  • It's working now...had to uncheck to return the UDF value.

  • This script is working really well, but I have two questions:

     

    1.  How can I modify this script to default the open file dialog box to a certain directory on the server?  Currently, the "select file" screen defaults to the ...\MAS90\Links folder.

     

    2.  Also, I'd like to only store the file name in the UDF, not the entire path...how can I modify the script to only store the filename and extension?

     

    Thanks!

  • What happens if you set an inital value for fileName?

     

    [EDIT] Never mind about this. Read on.