Please rate how useful you found this document: 
Average: 2.3 (4 votes)

Document Functions

PMFAddInputDocument()

PMFAddInputDocument() adds an Input Document file to a specified case.

string PMFAddInputDocument(string inputDocumentUID, string appDocUID, int docVersion, string appDocType = 'INPUT', string appDocComment, string inputDocumentAction, string caseUID, int delIndex, string taskUID, string userUID, string option = 'file', string file = 'path_to_file/myfile.txt')

Parameters:

  • string inputDocumentUID: The unique ID of the Input Document. This can be found by clicking on the UID button in the list of Input Documents or by using the following database query:
    SELECT INP_DOC_UID FROM INPUT_DOCUMENT WHERE INP_DOC_TITLE = '<INPUT-DOC-TITLE>'
  • string appDocUID: The unique ID of the file to be replaced or have a new version added. Set to null or "" (empty string) if adding a new file.
  • int docVersion: The document version, which starts numbering from 1. If adding a new version, increment the existing version by 1.
  • string appDocType: The document type, which is 'INPUT' for an Input Document file or 'ATTACHED' for an attached file (which is uploaded to a file field).
  • string appDocComment: The comment of the uploaded file.
  • string inputDocumentAction: The action, which can be: null or "" for add, "R" for replace or "NV" for new version.
  • string caseUID: The unique ID of the case to which the file will added. It can be found in the following ways:
    • Use the @@APPLICATION system variable to get the unique ID of the current case.
    • Use the PMFCaseList(), WSCaseList() or the caseList() web service.
    • Use executeQuery() to look up the case UID in the wf_<WORKSPACE>.APPLICATION.APP_UID field in the database.
  • int delIndex: The delegation index of the case to which the file will be added. It can be found in the following ways:
    • Use the system variable @%INDEX for the current case.
    • Use the PMFCaseList(), WSCaseList() or the caseList() web service.
    • Use executeQuery() to look up the delegation index in the wf_<WORKSPACE>.APP_CACHE_VIEW.DEL_INDEX field WHERE DEL_THREAD_STATUS='OPEN'.
  • string taskUID: The unique ID of the task, which can be found in the following ways:
    • Use the @@TASK system variable to get the unique ID of the current task.
    • Use the PMFTaskList() function or taskList() web service.
    • Query the wf_<WORKSPACE>.TASK.TAS_UID field in the database or get the starting task of the current process with the following query:
      executeQuery("SELECT TAS_UID FROM TASK WHERE PRO_UID='" . @@PROCESS . "' AND TAS_START='TRUE'");
  • string userUID: The unique ID of the user who is set as the uploader of the file.
  • string option: The option, which should be set to: "file" by default.
  • string file: The path of the file to be added, which is stored on the ProcessMaker server.

Return value:

  • Returns the unique ID of the added case file (AppDocument) if it was added successfully; otherwise, returns null or empty if an error occurred.

Example:

Create an Input Document in ProcessMaker. Look up its current ID and assign it to the variable named inputDocumentUID. Set the value of the application document ID to null and the value of the Document Action to 'add' if it is the first time the process is run.

inputDocumentUID = 757584323513f501410f3f3061256214 appDocUID = null inputDocumentAction = Add

Set the following trigger to be executed before the Input Document files are displayed:

@@fileId = PMFAddInputDocument('757584323513f501410f3f3061256214', null, 1, 'INPUT', 'Testing', 'Add',
   @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', 'c:\file.txt');

If the same document needs to be uploaded as a new version, copy the ID of the document previously added with the following parameters:

inputDocumentUID = 757584323513f501410f3f3061256214 appDocUID = 456268310513fa1b624c751021820069 //obtain this from the return variable while case is running or from the database wf_<WORKSPACE>.INPUT_DOCUMENT inputDocumentAction = 'NV'

Note: Don't forget to enable versioning when defining the Input Document. Otherwise, it won't be possible to upload another version of the same Input Document file.

PMFAssociateUploadedFilesWithInputFile()

PMFAssociateUploadedFilesWithInputFile() associates the files uploaded inside a grid with an Input Document. If the Dynaform contains more than one grid, the function should be used more than one time changing the parameters.

variant PMFAssociateUploadedFilesWithInputFile(string inputDocumentUID, string gridVariableName, string fileVariableName, string caseUID, string userUID, int delIndex)

Parameters:

  • string inputDocumentUID: The unique ID of the Input Document the user wants to associate with the uploaded files. This can be found by clicking on the UID button in the list of Input Documents or by using the following database query:
    SELECT INP_DOC_UID FROM INPUT_DOCUMENT WHERE INP_DOC_TITLE = '<INPUT-DOC-TITLE>'
  • string gridVariableName: The variable name of the grid that contains the uploaded files.
  • string fileVariableName: The variable name of the file.
  • string caseUID: The unique ID of the case to which the file will added. It can be found in the following ways:
    • Use the @@APPLICATION system variable to get the unique ID of the current case.
    • Use the PMFCaseList(), WSCaseList() or the caseList() web service.
    • Use executeQuery() to look up the case UID in the wf_<WORKSPACE>.APPLICATION.APP_UID field in the database.
  • string userUID: The unique ID of the user who is set as the uploader of the file.
  • int delIndex: The delegation index of the current case to which the file will be added. It can be found in the following ways:
    • Use the system variable @%INDEX for the current case.
    • Use the PMFCaseList(), WSCaseList() or the caseList() web service.
    • Use executeQuery() to look up the delegation index in the wf_<WORKSPACE>.APP_CACHE_VIEW.DEL_INDEX field WHERE DEL_THREAD_STATUS='OPEN'.

Return value:

  • Returns null or empty by default; if there is an error it will go through an exception.

Example:

The following trigger code associates the uploaded files in the grid with the @@gridVar variable to a file named file0000000001 in the current case:

@@return = PMFAssociateUploadedFilesWithInputFile("61499023457b392c30b6ec9010939119", @@gridVar, "file0000000001", @@APPLICATION, @@USER_LOGGED, @@INDEX);

PMFCopyDocumentCase()

PMFCopyDocumentCase() shares documents from one case with another case. For example, while sharing documents between a parent process and a subprocess.

string PMFCopyDocumentCase(string AppDocUID, int docVersion, string targetCaseUID, string InputDocumentUID)

Parameters:

    li>string appDocUID: The unique ID of the file in the source case. This ID can be found by querying the APP_DOCUMENT.APP_DOC_UID field in the database or by using json_decode(@@fileVariable)[0] for a File field or @=multipleFileVariable[N]['appDocUid'] for a MultipleFile field.
  • int docVersion: The document version number, which starts numbering from 1. If adding a new version, increment the existing version by 1.
  • string caseUID: The unique ID of the target case to which the document will be copied. It can be found in the following ways:
    • Use the @@APPLICATION system variable to get the unique ID of the current case.
    • Use the PMFCaseList(), WSCaseList() or the caseList() web service.
    • Use executeQuery() to look up the case UID in the wf_<WORKSPACE>.APPLICATION.APP_UID field in the database.
  • string InputDocumentUID: Optional. The unique ID of the Input Document in the target case. If not specified, then the file is uploaded as an attachment in the target case (not associated to any input document). This parameter can be found by clicking on the UID button in the list of Input Documents.

Return value:

  • Returns the copied document UID if the document was copied successfully; otherwise, returns an exception if an error occurred.

Example:

The following code copies the first version of a document with ID "43103027358111e9547f7a0093499626" to the current case:

@@result = PMFCopyDocumentCase("43103027358111e9547f7a0093499626", 1, @@APPLICATION, "");

PMFGenerateOutputDocument()

PMFGenerateOutputDocument() generates a specified Output Document, merging the variables from the current case into the Output Document's template. This function creates the Output Document file in the server file system and adds a new record to the wf_<WORKSPACE>.APP_DOCUMENT table. For more information, see Output Document Storage. If an Output Document has already been generated in the current case, this function will overwrite the existing Output Document file, or will add a new version of the file, if the versioning option is enabled.

void PMFGenerateOutputDocument(string outputUID, string application = null, integer delIndex = null, string userUID = null)

Parameters:

  • string outputUID: The unique ID of the Output Document, which can be found in 3 ways:
    • Look it up in the wf_<WORKSPACE>.OUTPUT_DOCUMENT.OUT_DOC_UID field in the database.
    • In the wf_<WORKSPACE> database, issue the query:
      SELECT OUT_DOC_UID FROM OUTPUT_DOCUMENT WHERE OUT_DOC_TITLE = '<OUTPUT-DOC-TITLE>'
    • Run a case with the Output Document as a step and examine the UID variable in the debugger.
  • string caseUID: The unique ID of the case to which the file will added. It can be found in the following ways:
    • Use the @@APPLICATION system variable to get the unique ID of the current case.
    • Use the PMFCaseList(), WSCaseList() or the caseList() web service.
    • Use executeQuery() to look up the case UID in the wf_<WORKSPACE>.APPLICATION.APP_UID field in the database.
  • int delIndex: The delegation index of the case from which the file will be generated.
  • string userUID: The unique ID of the user who is set as the uploader of the file.

    Note: If you are using the PMFGenerateOutputDocument() function in a Script task, the userUID parameter is required. Otherwise, if there is no user UID, it must be defined as null.

Return Value:
None.

Note: PMFGenerateOutputDocument() can be called at any point in a case, but if a variable included in the Output Document's template does not exist yet, the name of the variable will be inserted into the generated file instead of the value of the variable.

Examples:
1. If the template file of the Output Document contains a case variable set in the same trigger that calls PMFGenerateOutputDocument(), then the case variable will have to first be saved to the database using the PMFSendVariables() function.

For example, the template contains the variables @#ClientName and @#AccountNumber. Those variables will be saved to the database with PMFSendVariables() before calling PMFGenerateOutputDocument().

$vars = array("ClientName" => "Sally Simpson", "AccountNumber" => "G2938-238");
$result = PMFSendVariables(@@APPLICATION, $vars);
//Returns 1 if the variables were sent successfully to the case
if ($result) {
    $docId = '954109698491477e1986b43042252891'; //output document unique ID
   PMFGenerateOutputDocument($docId);
}

2. Generate an Output Document in the current case, then open the HTML file that was generated for it and insert it into an email template named "outDocMail.html", which has the inserted variable @#mailBody:

$docId = '954109698491477e1986b43042252891'; //set to the Output Document's unique ID
PMFGenerateOutputDocument($docId);
//find the generated Output Document in the wf_&<WORKSPACE>.APP_DOCUMENT table
$query = "SELECT MAX(DOC_VERSION) AS MAX_VERSION, APP_DOC_UID FROM APP_DOCUMENT
   WHERE APP_UID = '$caseId' AND DOC_UID='$docId'"
;
$result = executeQuery($query);
$g = new G();
if (is_array($result) and count($result) > 0) {
   $pathFilename = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP . 'outdocs'. PATH_SEP .
      $result[1]['APP_DOC_UID'] . '_' . $result[1]['MAX_VERSION'] . '.html';
   $body = file_get_contents($pathFilename);
   PMFSendMessage(@@APPLICATION, 'theboss@example.com', userInfo(@@USER_LOGGED)['mail'], '', '',
      'Generated Output Document', 'outDocMail.html', array('mailBody' => $body));
}

To send a generated Output Document file as an attachment in an email, see this example.

3. Generate an Output Document in the current case and then look up the generated Output Document file in the APP_DOCUMENT table. Copy the generated DOC and PDF files to another directory in the same server using the copy() function and to a remote server using the ssh2_scp_send() function.

$caseId = @@APPLICATION;
$docId = '954109698491477e1986b43042252891'; //set to the Output Document's unique ID
PMFGenerateOutputDocument($docId);
//find the generated Output Document in the wf_<WORKSPACE>.APP_DOCUMENT table
$query = "SELECT MAX(DOC_VERSION) AS MAX_VERSION, APP_DOC_UID FROM APP_DOCUMENT
   WHERE APP_UID = '$caseId' AND DOC_UID='$docId'"
;
$result = executeQuery($query);
$g = new G();
if (is_array($result) and count($result) > 0) {
    $docPath = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP . 'outdocs'. PATH_SEP;
    $filename = $result[1]['APP_DOC_UID'] . '_' . $result[1]['MAX_VERSION'];

    //copy to another directory on the same server:
    $otherDir = 'C:\path\to\file\\'; //set to path for another directory
    copy("$docPath$filename.doc", "$otherDir$filename.doc"); //if generating DOC files
    copy("$docPath$filename.pdf", "$otherDir$filename.pdf"); //if generating PDF files

    //copy to a remote server:
    $remoteDir = '/path/to/file/'; //set to directory path on remote server
    $conn = ssh2_connect('www.example.com', 22); //set to URL for remote server
    ssh2_auth_password($conn, 'username', 'password'); //set the username and password
    ssh2_scp_send($conn, "$docPath$filename.doc", "$remoteDir$filename.doc");
    ssh2_scp_send($conn, "$docPath$filename.pdf", "$remoteDir$filename.pdf");
}

4. To generate an Output Document file using a script task, create the script task after a user task and in the script call PMFGenerateOutputDocument using only the attribute outputUID. There is no inconvenience as the script task completes the other attributes with the information of the previous task.

But in the particular scenario where another process elements diferent to a user task like a sub-process or timer event precedes the script task, it is imperative that you send all the attributes to the script task because there is no previous information from which the script task can complete the information.

As an example you can use the following code as a guide:

PMFGenerateOutputDocument('954109698491477e1986b43042252891', @@APPLICATION, @@INDEX, '00000000000000000000000000000001');