Display an error message if File upload failed

From pmusers
Jump to: navigation, search

MultipleFile fields display a progress bar that indicates if the upload failed. File fields, however, upload the file after the Dynaform is submitted, so there is no indication to the user that an upload failed if Debug Mode is not enabled to see the error message in the @@__ERROR__ system variable.

To display an error message if an upload to a File field failed, create the following trigger:

//set to the ID of the Dynaform where File is uploaded:
$dynaformId = '1234567890abcdef1234567890abcdef'; 

if (isset(@@__ERROR__)) {
   $err = @@__ERROR__;
   $g = new G();
   $g->SendMessageText($err, "ERROR");
   unset(@@__ERROR__); //clear error so it won't be detected the next time
    
   //if you want the case to return to the Dynaform where file failed in uploading:
   PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}

The G::SendMessageText() function is used to display an error message above the Dynaform when it is redisplayed with the PMFRedirectToStep() function. Redisplaying the Dynaform which contains the File field allows the user to upload the file again. Remember that G::SendMessageText() won't work if it is executed after routing because the message will be overwritten when the case list is displayed.

Then set this trigger to fire before the next step or before assignment if the Dynaform is the last step in the task. Do NOT set it to fire immediately after the Dynaform, because at that point the file as not yet been saved in the database and placed in the server's file system.