This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to run a VBscript when import documents using External Source

Former Member
Former Member
Hi,

Im using EXTERNAL SOURCE feature to import PDF files using XML to get data, I need to import only PDF files that have a XML file, Im trying  using a event handler ( BeforeCreateNewObjectFinalize ) but it doesnt Works when import documents using EXTERNAL SOURCE, how can I resolve this issue ??

Regards,
  • Hi Manuel,

    Event handlers such as BeforeCreateNewObjectFinalize definitely run when using external sources. I've used them before (perhaps not BeforeCreateNewObjectFinalize, but event handlers in general) to do file analysis and metadata population as part of the import.

    However, I'm not sure you'll be able to trap whether an associated XML file exists or not at this point. The best you may be able to do is to tell M-Files to load metadata from the XML file and then have an event handler that ensures the metadata is loaded and throws an exception if it is not. I've not tried this before, but it may stop the file from being imported.

    Alternatively, can you intercept the file being written to the external source location and only copy it there if the XML file exists too?

    Craig.
  • Former Member
    Former Member
    Hi Craig,

    Thanks for your support, I checked again my code and I modified as follow:


    ' Create text file to log information about this issue
    Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\temp\listfile.txt",2,true)
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Dim titleProperty
    titleProperty = MFBuiltInPropertyDefNameOrTitle

    Dim currentTitleProp
    dim filePDF
    dim fileXML

    currentTitleProp = PropertyValues.SearchForProperty(titleProperty)
    filePDF = "D:\Recepcion\Documentos\InformesDeReparto\" & currentTitleProp & ".pdf"
    fileXML = "D:\Recepcion\Documentos\InformesDeReparto\" & currentTitleProp & ".xml"

    objFileToWrite.WriteLine(filePDF)
    objFileToWrite.WriteLine(fileXML)
    objFileToWrite.WriteLine(currentTitleProp)

    If objFSO.FileExists(filePDF) = false or objFSO.FileExists(fileXML) = false Then
    objFileToWrite.WriteLine("Falta el Archivo PDF o XML")
    Err.Raise MFScriptCancel, "Falta el Archivo PDF o XML"
    end if

    objFileToWrite.WriteLine("ARCHIVO IMPORTADO CON EXITO")
    objFileToWrite.Close
    Set objFileToWrite = Nothing

    And works fine !!!!, but I have a doubt, I tried to use Dim file As System.IO.StreamWriter but I got error, Im confusing, I have to use VBScript or Visual Basic ??
  • Hi Manuel,

    "Dim file As System.IO.StreamWriter" looks like VB.NET to me; event handlers are written in plain Ol' VBScript I'm afraid.

    Craig.