Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By twforumguy
#815796
Hi there,
I 'm building a process where I want to put Dynaform-data into a .xml-file (i.e. a template) and send it via ftp to a server and right now I've got a major problem:
The users don't have the xml-template-file so there is no way to upload it into each case as an input file. Therefor I'm looking for a solution to add the file to each case in advance. I already uploaded it to the "documents"-section into a folder. Now my question is: how do I add the file to a case, access it in a trigger, make a copy of it, fill it with my Dynaform-data and save it as a new file?

Thanks for your help.
M.
User avatar
By amosbatto
#815797
You can store the xml file in Home > Documents (but then it is subject to restrictions on who can download it) or in the Public Files of a process (with no download restrictions, but also no security if it is confidential information).

Download the file and then copy the download URL from your web browser, so that you can use it in your trigger code.

Then, you can use trigger code like this:
Code: Select all
//set to URL of XML file:
$xmlFileUrl = "http://localhost:321/sysworkflow/en/neoclassic/cases/cases_ShowDocument?a=1103373095aa6d369f14501012383506&v=1";

$xmlContents = file_get_contents($xmlFileUrl) or die("Unable to open URL $xmFileUrl"); 

//insert case variables in XML file:
//modify regular expressions for the fields that you want to insert:

//if xml fields are empty:
$xmlContent = preg_replace('/(<some_xml1>)\s*(<\/some_xml1>)/', '$1'.@@var1.'$2', $xmlContents); 
 
//if replacing values in xml fields:
$xmlContent = preg_replace('/(<some_xml2>).*?(<\/some_xml2>)/', '$1'.@@var2.'$2', $xmlContents); 

//save file on ProcessMaker server:
$newXmlFilePath = "/path/to/new/file.xml";  
file_put_contents($newXmlFilePath, $xmlContent) or die("Unable to write to file '$newXmlFilePath'.");

//If wanting to add file to case:
$inputDocId = '757584323513f501410f3f3061256214',
@@fileId = PMFAddInputDocument($inputDocId, null, 1, 'INPUT', 'Updated XML File', 'Add',
   @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $newXmlFilePath);

//if wishing to delete file on PM server:
unlink($newXmlFilePath);
PS: Google the functions that you don't understand.
By twforumguy
#815809
Hi Amos,
thank you very much. That helped a lot.
For others who might have the same problem I'd like to add that "/path/to/new/file.xml" might be solved with:

$newXmlFilePath = PATH_DATA_PUBLIC.PATH_SEP."file.xml";
But be aware that this path is publicly accessible.

Try the CloudMigration PST Converter to convert […]

In the rapidly evolving world of online sports be[…]

STEPN integrates social networking and games that […]

Cenforce 150 is a medication used to cope with a c[…]