[C# PW API] Workflow Rules Engine - push document to next state

Hi all,
I have been attempting to push a document to a different state using the aaApi_WREDoExecute method listed in the API. Everything seems to be working to a certain degree, except the response I get is: "Execution command identifier '{urn:bentley:wre:command:__1_1_REVISE__}' not recognized".

Is there perhaps a syntax error in the command Id I used within the aaApi_WRECreateExecuteDescription method? Not sure what it is though since I have tried a number of different combinations with no luck. The "command id" value was generated using the aaApi_WREAskCommands method, which returned this comamnd id as one of the commands available for that document.

Any suggestions or help would be greatly appreciated!

Thanks,


Edward

  • Found the solution... the aaApi_WREDoExecute example in the documentation is incorrect: aaApi_WRECreateExecuteDescription does not take an array for the command id, it just takes a single command id (no curly brackets). Once I changed that everything worked as expected!

    so aaApi_WRECreateExecuteDescription(document, "{my-command-id}");
    becomes aaApi_WRECreateExecuteDescription(document, "my-command-id");

    Answer Verified By: Edward Ashbolt 

  • Hello, 

    This is really interesting and useful.

    Try to get WRE running as well, but cant command id.

    The ID what I set from Rules engine did not work, like Nextstate

    How did you get manage to work aaApi_WREAskCommands?

    Thanks

    Darius

  • Hi Darius,

    You need to use the aaApi_WREAskCommands method to query for the id using the command "label", eg.

    //Retrieve commands list
    IntPtr commandsRequest = PWWrapper.aaApi_WREAskCommands(request);
    IntPtr commandsList = PWWrapper.aaApi_DmsDataBufferGetBufferProperty(commandsRequest, DMS_WRE_COMMANDS_COMMANDS, 0);
    int commandsCount = PWWrapper.aaApi_DmsDataBufferGetCount(commandsList);
    
    //Get each command available
    for (int i = 0; i < commandsCount; ++i)
    {
        string label = PWWrapper.aaApi_DmsDataBufferGetStringProperty(commandsList, DMS_WRE_COMMAND_LABEL, i);
        if (label.StartsWith(commandLabel, StringComparison.OrdinalIgnoreCase))
        { 
            cmdId = PWWrapper.aaApi_DmsDataBufferGetStringProperty(commandsList, DMS_WRE_COMMAND_ID, i);
            break;
        }
    }

  • Thanks a lot Edward, helped so much!!!

    Finally I managed to run Rules engine using API.

    There is one interesting situation. When I run this command not from PW client, but use third application, login to PW data source it works fine. The problem is when I try do exactly the same from active PW client session, I just go out from execution, no warning, no errors.

    It just return back to the session. Try{} catch{} do not get anything.

    I get this problem on aaApi_DmsDataBufferSetBufferProperty.

    Not sure what is wrong.

    IntPtr requestCmd = PWWrapper.aaApi_WRECreateCommandsRequest("en");
    IntPtr documents = PWWrapper.aaApi_DmsDataBufferGetBufferProperty(requestCmd, 2, 0);
    IntPtr document = PWWrapper.aaApi_WRECreateDocumentIdentifier("{" + docGuid + "}");
    PWWrapper.aaApi_DmsDataBufferAppend(documents, document, 0, 0);
    PWWrapper.aaApi_DmsDataBufferSetBufferProperty(requestCmd, 2, 0, documents);

    Best regards

    Darius

  • Hard to say what the issue would be without more information. A few things you could check:

    • Make sure you're not loading any assemblies that have already been loaded in PW Explorer Client, and that all assemblies are located. I suspect that is your issue if it fails immediately
    • Don't login if you are already in an active session
    • Check that you have initialised the api via aaApi_Initialize(0) (normally done for you at login, but you don't need a login)
    • See if you can identify the exact point it fails by debugging in your IDE. If you can't trap the error and it fails immediately, try separating all of the command logic into a separate class / method so that you can trap with a try catch statement at the entry point

    Hope that helps