Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#812488
I have a process that includes an input document and has a dynaform with a file field on it. The file field has a variable tied to the input document. I use REST to create a case and then use REST to upload the input document into the case. That all works as expected. I then try to set the variable in the case with the UID for the uploaded document (actually, an array with a single string which is the UID) and set the variable plus a _label suffix to the file name (actually, an array with a single string which is the filename). When I go into the form however, I expect to see the file linked in there, and it is not. What am I missing?

Here is the result of the Upload:
{"app_doc_uid":"9478154835a29b5a32eb0c9016093062","app_doc_filename":"0216001304.jpg","doc_uid":"2085262685a1fe190b72e10068083144","app_doc_version":"1","app_doc_create_date":"2017-12-07 16:41:55","app_doc_create_user":"admin, Administrator (admin)","app_doc_type":"INPUT","app_doc_index":1,"app_doc_link":"cases\/cases_ShowDocument?a=9478154835a29b5a32eb0c9016093062&v=1"}

Here is the result of GET variables on that case after I set the fileVar002 and fileVar002_label fields (as per "Files" section of http://wiki.processmaker.com/3.2/REST_A ... _Variables):
{"SYS_LANG":"en","SYS_SKIN":"neoclassic","SYS_SYS":"workflow","APPLICATION":"","PROCESS":"","TASK":"","INDEX":"","USER_LOGGED":"","USR_USERNAME":"","APP_NUMBER":"38","PIN":"4Z63","firstName":"Dave","fileVar002":["9478154835a29b5a32eb0c9016093062"],"fileVar002_label":["0216001304.jpg"]}"
#812490
ProcessMaker doesn't look at the variable when displaying a file field. Instead it queries the APP_DOCUMENT table, looking for records where the APP_DOC_FIELDNAME field is set to the name of the variable.

The problem is that the POST /cases/{app_uid}/input-document endpoint doesn't have a option to set the APP_DOC_FIELDNAME. (I will file a bug report about this so it will get fixed in future versions.)

One way to get around this problem is to create the following trigger in your process:
Code: Select all
if (!isset(@@newFileId) or empty(@@newFileId)) {
    throw new Exception("Need to set the variables @@newFieldId and @@fileVarName");
}

$sql = "UPDATE APP_DOCUMENT SET APP_DOC_FIELDNAME='".@@fileVarName.
       "' WHERE APP_UID='".@@APPLICATION."' AND APP_DOC_UID='".@@newFileId."'";
@@result = executeQuery($sql);   
This trigger doesn't need to be set to execute at any point in the process. It just needs to exist in the process.

Then, in your external script, first call PUT /cases/{app_uid}/variable to set the "newFileId" variable to the ID of app_doc_uid and set "fileVarName" to "fileVar002".
Then, call PUT /cases/{app_uid}/execute-trigger/{tri_uid} to execute the above trigger.
#812508
Oh, I forgot a very important step. If you are using PM 3.0.1.8 or later, then you will have to edit your execute-query-blacklist.ini file and change this line from:
Code: Select all
queries="INSERT|UPDATE|REPLACE|DELETE"
To:
Code: Select all
queries="INSERT|REPLACE|DELETE"
See: http://wiki.processmaker.com/3.0/Consul ... ore_Tables
I keep running into a problem where it doesn't consistently set both variables.
You should be able to set both of the variables at the same time with this endpoint: PUT /cases/{app_uid}/variable
If you can't, then post your code and I will look at.
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]