The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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

Call external program from workflow

Hello,

I am trying to call a custom app from workflow in M-Files (from vbcript). Version of M-Files is 21.6.10322.8.

So, I created new console application (ConsoleApp1) in Visual Studio 2019

namespace ConsoleApp1
{
   class Program
   {
       static void Main(string[] args)
       {
              Console.WriteLine("TEST");

              // code below writeline  never gets executed from workflow

              var app = new MFilesAPI.MFilesClientApplication();
              var vaults = app.GetVaultConnections();

        }

}

}

My intention here is to have c# code which would connect to a particular vault in M-Files and upload documents. And I have such code in this app, and that works when I start that ConsoleApp1.exe directly from Visual Studio or Windows Explorer.

In M-Files, I created workflow with one state (s1) which has VBScript:

Option Explicit

Dim objWScript
Set objWScript = CreateObject("WScript.Shell")

Dim objExec
Set objExec = objWScript.Exec("c:\test\ConsoleApp1.exe")

And, when I start the workflow and set state to s1, message is displayed "TEST", but after that, there is an error:

CoScriptObjectFactory.cpp, 465, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
ScriptErrorHelper.cpp, 96, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MDispatchExImpl.h, 694, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MDispatchExImpl.h, 994, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MetadataCardAction.cpp, 386, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MetadataCardAction.cpp, 570, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MetadataEditor.cpp, 2967, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MetadataModel.cpp, 4244, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MetadataModel.cpp, 4681, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
ElectronicSignatureUIHelper.cpp, 235, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MetadataModel.cpp, 12169, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
CoVaultMountingDocumentOperations.cpp, 3204, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
DocumentCache.cpp, 11284, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
DocumentCache.cpp, 11393, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
DocumentCache.cpp, 19560, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCMethodCallWithRetry.h, 35, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCMethodCallWithRetry.h, 35, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperations.cpp, 12721, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperations.cpp, 7386, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
MCallInLoop.h, 712, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 4157, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 3718, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 9423, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 10014, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 27602, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 2908, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 3120, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 3540, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 4379, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((s1, StateAction: 4-12)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 328, No M-Files error description available. (0x80040007)
VaultScriptSessionTemplates.cpp, 510, No M-Files error description available. (0x80040007)
CoActiveScriptSite.cpp, 894, No M-Files error description available. (0x80040007)
CoActiveScriptSite.cpp, 736, No M-Files error description available. (0x80040007)
s1, StateAction, 11, No M-Files error description available. (0x80040007)
MErrorHelper.cpp, 2449, No M-Files error description available. (0x80040007)
(M-Files 21.6.10322.8)

And whatever code is there, it doesn't matter, M-Files will return error and nothing else.

I repeat, ConsoleApp1.exe works great when started directly from Windows Explorer, but not from M-Files workflow.

What am I doing wrong?

Parents
  • You say that "TEST" is shown.  Shown how/where?

    Generally what you're trying to do is not something we'd guide people towards.  If you want to write C# code in response to a vault event then you should probably be looking at the Vault Application Framework.

    Regards,

    Craig.

  • Thanks for the very quick response.

    This is how the message form Console.Writeline is shown in M-Files:

    Actually, it doesn't matter what the code after that is.

    What I need is to call external app from M-Files workflow.

    That external app would do something with the file and then return the file back to M-Files.

  • The "Console.WriteLine" call is being treated as an exception by M-Files so the application does not execute any further.  I assume this is something to do with it writing to the standard output, but I don't know why M-Files treats it as an exception.  I'm sure there's a logical reason.  If you removed this line then your application would probably continue to run.

    As I said, though, this is not a recommended approach.  You should instead interact with the vault directly within VAF code, rather than running an application that creates a separate connection to the vault.

  • If I remove "Console.WriteLine", instead of "TEST" I get "No M-Files error description available" (and the same error message as in my initial post). Regardless of what is written in that c# code. I have deleted all lines, response is the same.

    About the approach:

    I need to call external app after document is approved (in workflow). Each approved document must go through that app (this is custom unknown app, which could be exe file or web service). So, I suppose I have to do it from workflow? I can use VAF for that?

    I am just starting with M-Files development so I apologize for my ignorance. 

  • Hi Mario,

    In general: you should be communicating with that web service (or application, via an API) directly from the VAF, from within a workflow state action.

    If you work for a partner then please reach out to your Channel Account Manager for details on what assistance we can provide to help you on this.  If you work for an end-user then all of our public documentation is available on https://developer.m-files.com, and your partner may be able to provide you with additional training and support.

    Of course, feel free to continue to ask questions, but there's a limited amount we can do to structure your learning via a forum.

    Regards,

    Craig.

  • Well, obviously I have a problem with the M-Files installation or my environment because nothing works as expected.

    I tried to deploy following solution

    https://developer.m-files.com/Frameworks/User-Interface-Extensibility-Framework/Visual-Studio/

    I didn't make any changes, I just build it and install the mfappx file and nothing happens, "My dashboard" isn't visible.

    I tried another example:

    https://developer.m-files.com/Samples-And-Libraries/Samples/User-Interface-Extensibility-Framework/HelloWorld/

    Also, just download files and install to vault, nothing happens.

    I don't know anymore, maybe it has something to do with permissions...

    Thanks for the help, but it seems that there is some kind of problem with my environment

  • The examples you've pointed to are client-side ("UIX") applications, whereas you want server-side ("VAF") applications.  To try a VAF application you can install the templates to your Visual Studio, create an application, then create a state action or event handler.

    You can attach a debugger and see whether these are firing.

    Can you send me a private message with details about the company you work for?  I may be able to guide you on what support can be offered.

    Regards,

    Craig.

Reply Children