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 modify Word document from M-Files Server VBScript?

Former Member
Former Member
I want to create a script on M-Files server that sets "Track Changes" when a Word document enters a certain state and "Accept All Changes and Stop Tracking" when the document enters a later state.

State Draft: "Track Changes"
State Submitted: -
State Reviewed: -
State Accepted: "Accept All Changes and Stop Tracking"
State Issued: - (next state is Draft for next major version of document)

I found the place in M-files Server Administrator to create the VB Script: Vault/Workflows/Properties/State/Edit/Actions/Run Script

According to the documentation the following variables can be used in the script: VaultSharedVariables, MFScriptCancel, CurrentUserID, Vault, DisplayID, ObjVer, PropertyValues, and StateID.

In Word VBScript I can set this propertiy by with:

ActiveDocument.TrackRevisions = True

How to do the same from M-Files server script?

Best regards

Erik
  • Former Member
    Former Member
    Hello again,

    I managed to start Word from my script:

    Dim word: Set word = CreateObject("Word.Application")

    The question now is how to specify the file name (docxFile) to be able to open the word document? I want to do the following:

    Dim doc: Set doc = word.Open(docxFile, false)
    doc.TrackRevisions = True

    When I try to print out ObjVer.GetNameForFileSystem I don't get any result in my log file.

    In the M-Files client I can locate the file manually at M:\yellow\Favorites\Bosa Copy (ID 108).docx

    On the M-Files server, when I search for the file I only find the database. D:\M-Files\Server Vaults\yellow.

    Is there a way to access the file (and use as parameter to Word) on the M-Files server?
  • If you are implementing M-Files Client API app, check out the GetPathInDefaultView Method in the API documentation to get the ID path, from which you can access the file.

    Mika
  • Former Member
    Former Member
    Hello Mika,

    No, I'm using the M-Files Server API. But thanks for the try.

    According to the M-Files support it is not an easy operation to access and update the Word document on the server side.
  • Former Member
    Former Member
    Hello,
    any movement on this? I have document template Agreement (MS Word file) which consists from topics and table of items. Item's comes from standalone objects joined with Agreement via metadata field "Agreement". I need to change item's table content in DOC file if any items have changed.

    It's possible to go this way?

    Thanks,

    Martin

  • I have document template Agreement (MS Word file) which consists from topics and table of items. Item's comes from standalone objects joined with Agreement via metadata field "Agreement". I need to change item's table content in DOC file if any items have changed.

    It's possible to go this way?


    This is a little different question but there are a few things you can do:

    You can update the metadata fields on the server-side when the file is delivered from server to (any client). See chapter 6.4:
    kb.cloudvault.m-files.com/Default.aspx

    You can update and modify Office documents programmatically with something like Aspose. So you can call Aspose dll in your event handlers and vault applications:
    https://www.aspose.com/

    Mika
  • Have you considered downloading the file to the server, make the desired change, and then upload the document back to M-Files replacing the existing file.