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.
By tamasig
#812698
Dear All,

I am using ProcessMaker 3.0.1.7-community, and I cannot seem to find a way to empty a file control for a second/third/etc. loop once a file has been submitted. I have tried deleting the input document in the process; emptying the file variable array as well as setting it to an empty array with json_encode in a PHP trigger; setting the variable_label variable; etc., but nothing seems to work: the file previously submitted remains stubbornly in the file control, causing much pain and confusion.

Any and all help would be much appreciated.

With best wishes,
Gergely
By tamasig
#812713
Many thanks, Amos, for the quick reply; however, I am afraid that the code I found under AppDocument::remove() in the ProcessMaker wiki, which should theoretically remove all files associated with the case, accomplishes neither: it did not remove the file from the file system or the file control.
ScreenShot.png
ScreenShot.png (26.88 KiB) Viewed 5985 times
On previous attempts, I tried to use the input document as a step in the task so that I can remove the document manually, but even in that case the document stays in the file control. (N.B. I am using 3.0.1.7, so I do not have access to the multiple file uploader. I can remove the file before submitting the form from the file control with the delete button I added, only not after that.) Any thoughts?

Gergely
User avatar
By amosbatto
#812715
There is a bug in the File control which causes it to ignore the fact that the status of the file is set to "DELETED". The workaround is to set the APP_DOCUMENT.APP_DOC_FIELDNAME to an empty string, so the file is no longer associated with the File control.

You can use this trigger code:
Code: Select all
if (isset(@@specFile) and !empty(@@specFile) and @@specFile != '[]') {
    $fileId = json_decode(@@specFile)[0];
    $sql = "UPDATE APP_DOCUMENT SET APP_DOC_FIELDNAME='' WHERE APP_DOC_UID='$fileId' AND 
            APP_DOC_STATUS='ACTIVE' ORDER BY DOC_VERSION DESC LIMIT 1";
    @@result = executeQuery($sql);
} 
where "specFile" is the name of the variable associated with the File control. This trigger cannot be executed immediately after the DynaForm containing the File control, because a record has not yet been created in the APP_DOCUMENT table in the database for the file. Instead, it can be executed before the next step or before assignment if the DynaForm is the last step in the task.

See the attached sample process:
(25.95 KiB) Downloaded 358 times
PS: If you need to use this code in PM 3.0.1.8 or later, then you will need to edit your workflow/engine/config/execute-query-blacklist.ini file and change the 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
By tamasig
#812721
Hey,

Many thanks for sending me the .pmx file. I uploaded it into my system, but I am afraid it still does not work:
Screen Shot 2018-01-06 at 15.20.38.png
Screen Shot 2018-01-06 at 15.20.38.png (33.49 KiB) Viewed 5964 times
Any alternatives that come to mind? :-/

Many thanks for all your help.

Gergely
User avatar
By amosbatto
#812747
The process works to remove the file from the File control in the DynaForm. You have to start a case and select a file and then click on "Submit" in the DynaForm. Then complete Task 1 and you will be routed back to Task 1. When you open Task 1 the second time, you will see that the file doesn't appear in the File control.

However, if you want the file to also be deleted from the Input Document step, then you will also have to use the AppDocument::Remove() function as well in your trigger code.
User avatar
By amosbatto
#812763
Oh, I see the problem. Your version of PM is very out of date. In version 3.0.1.7 there is no @@file variable defined, just the @@file_label. OK, you need to use this trigger code:
Code: Select all
if (isset(@@specFile_label) and !empty(@@specFile_label) and @@specFile_label != '[]') {
    $caseId = @@APPLICATION;
    $sql = "UPDATE APP_DOCUMENT SET APP_DOC_FIELDNAME='' 
       WHERE APP_UID='$caseId' AND APP_DOC_FIELDNAME='specFile' 
       AND APP_DOC_STATUS='ACTIVE' ORDER BY APP_DOC_CREATE_DATE DESC LIMIT 1";
    @@result = executeQuery($sql);
}
Where "specFile" is the name of the variable associated with the File field.

If you want to seamlessly and hassle-free conversi[…]

Well many students have no idea how to write a goo[…]

Modalert 200 MG is a brand name for the generic dr[…]

Fildena double 200 mg capacity to move the relaxin[…]