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.
#788875
This can be done by creating a trigger to generate an output document and firing the trigger after the dynaform on a specific condition.

In the dynaform, take the following web controls:
* a hidden field(named action)
* a submit type button(to generate the output document on its click)
* a link field(where you can download the output document)

Write the following javascript in the dynaform:
Code: Select all
hidelink();
function hidelink(){
  var action = $("#action").getValue();
  if(action != "output" ){
  $("#filelink").hide();
  }
}
$("#opdoc").find("button").click(function(){
  $("form").saveForm();
  $("#action").setValue("output");
  $("#filelink").show();
});
$("#submit0000000001").find("button").click(function(){
	$("#action").setValue("");	
});
Here, opdoc is the ID of the button which generates the output document.
Set the value of action to "output" for generating output and "" to submit the form.

Create a trigger with the following code:
Code: Select all
if(@@action == "output"){
	$outputid = "502792749586c9ae036e5e5086358080";
	$case = @@APPLICATION;
	PMFGenerateOutputDocument($outputid);
	$query = "SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='$case' AND DOC_UID='$outputid' AND APP_DOC_STATUS='ACTIVE'";
	$result = executeQuery($query);
	if (!is_array($result) or count($result) == 0) {
	   die("Error: Unable to find generated Output Document in database.");
	}
	$d = new AppDocument();
	$aFile = $d->Load( $result[1]['APP_DOC_UID'] );
	@@outDocUrl = 'http://' . $_SERVER['SERVER_NAME'] .
		'/sys'. @@SYS_SYS . '/en/neoclassic/cases/cases_ShowOutputDocument?a=' .
	   $aFile['APP_DOC_UID'] . '&v='. $aFile['DOC_VERSION'] . '&ext=pdf';
	@@outDocFilename = $aFile['APP_DOC_FILENAME'] .'_'. $aFile['DOC_VERSION'] .'.pdf';
	PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', '952915093586c9ae036af54027049960');
}
This trigger generates an output document and stores the link for it in @@outDocUrl. It then redirects the flow back to the same dynaform.
Set this trigger to fire after the dynaform on the condition: @@action == "output"

Hope this helps
#788886
Thank you very much.

I think I see how this works. So this code basically still sets off the document creation after the dynaform in the trigger still but then redirects it back to the same dynaform.

Redirect:
Code: Select all
   PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', '952915093586c9ae036af54027049960');
And this code resets the "action" variable to nothing so it won't fire after the dynaform is submitted regularly.
Code: Select all
   $("#action").setValue("");
Is that right?

In the redirect code, 952915093586c9ae036af54027049960 is the dyanform ID?

I'm wondering if you could make your code more universal (for copying and sharing) if you added this:
Code: Select all
   $taskId = @@TASK; //get ID for current task
   $result = executeQuery("SELECT STEP_UID_OBJ FROM STEP WHERE TAS_UID='$taskId' and STEP_POSITION = 3");
   @@stepUidObj= $result[1]['STEP_UID_OBJ'];
   PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', @@stepUidObj);
}
Or am I not understanding the code from this documentation correctly?
http://wiki.processmaker.com/3.0/Proces ... Step.28.29

I'm not 100% sure what "STEP_POSITION = 3" is doing. Is it because dynaforms are in STEP_POSITION 3? Does that change if there are multiple dynaforms in a task?

I'm also not sure how the above code could be integrated with the first code. I'm assuming that I can't just do this:
Code: Select all
if(@@action == "output"){
   $outputid = "502792749586c9ae036e5e5086358080";
   $case = @@APPLICATION;
   PMFGenerateOutputDocument($outputid);
   $query = "SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='$case' AND DOC_UID='$outputid' AND APP_DOC_STATUS='ACTIVE'";
   $result = executeQuery($query);
   if (!is_array($result) or count($result) == 0) {
      die("Error: Unable to find generated Output Document in database.");
   }
   $d = new AppDocument();
   $aFile = $d->Load( $result[1]['APP_DOC_UID'] );
   @@outDocUrl = 'http://' . $_SERVER['SERVER_NAME'] .
      '/sys'. @@SYS_SYS . '/en/neoclassic/cases/cases_ShowOutputDocument?a=' .
      $aFile['APP_DOC_UID'] . '&v='. $aFile['DOC_VERSION'] . '&ext=pdf';
   @@outDocFilename = $aFile['APP_DOC_FILENAME'] .'_'. $aFile['DOC_VERSION'] .'.pdf';
   $taskId = @@TASK; //get ID for current task
   $result = executeQuery("SELECT STEP_UID_OBJ FROM STEP WHERE TAS_UID='$taskId' and STEP_POSITION = 3");
   @@stepUidObj= $result[1]['STEP_UID_OBJ'];
   PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', @@stepUidObj);
}
#788894
Zainab,
This is a great code example. I will use it for the wiki. Thanks.

ekaboom,
Yes, the Step position is the position in the task. For example, if you have a task with the following steps:
DynaformA, InputDocumentA, DynaFormB
Then the step position is 1 for DynaformA, 2 for InputDocumentA, 3 for DynaFormB.

You can make the trigger a bit simpler with this code:
Code: Select all
if(@@action == "output"){
   $outputId = "502792749586c9ae036e5e5086358080"; //Set to ID of Output Document
   $fileId = PMFGenerateOutputDocument($outputId);
   if (empty($fileId)) {
      throw new Exception("Error: Unable to generate Output Document.");
   }
   $d = new AppDocument();
   $aFile = $d->Load( $fileId );
   @@outDocUrl = (G::is_https() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . 
      ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'.$_SERVER['SERVER_PORT']) .
      '/sys'. @@SYS_SYS . '/en/neoclassic/cases/cases_ShowOutputDocument?a=' .
      $fileId . '&v='. $aFile['DOC_VERSION'] . '&ext=pdf';
   @@outDocFilename = $aFile['APP_DOC_FILENAME'] .'_'. $aFile['DOC_VERSION'] .'.pdf';
  
   $formTitle = 'Client Info'; //set to the title of your DynaForm
   $formId = PMFGetDynaformUID($formTitle, @@PROCESS);
   if (empty($formId)) {
      throw new Exception("Error: '$formTitle' is not the title of a DynaForm in the current process.");
   }
   else {
      PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $formId);
   }
}
This way the code should work even if the step position changes.
#788908
Could you do something similar for a button that sends an email?
Javascript:
Code: Select all
$("#emailButton").find("button").click(function(){
  $("form").saveForm();
  $("#action").setValue("email");
});
$("#submit0000000001").find("button").click(function(){
   $("#action").setValue("");   
});
Trigger:
Code: Select all
if(@@action == "email") {
  $aFields = array('ownerName' => @=ownerName, 'ownerEmail' => @=ownerEmail, 'endRangeDate' => @=endRangeDate, 'startRangeDate' => @=startRangeDate, 'salesEmail' => @=salesEmail);
  $usr = userInfo(@@USER_LOGGED);
  $from = $usr['mail']; 
  
  PMFSendMessage(@@APPLICATION, $from, @@ownerEmail, @@salesEmail, '', 'Please Send Me Your Sales Numbers ASAP', 'salesNumbers.html', $aFields);

   $formTitle = 'Request Sales Numbers'; //set to the title of your DynaForm
   $formId = PMFGetDynaformUID($formTitle, @@PROCESS);
   if (empty($formId)) {
      throw new Exception("Error: '$formTitle' is not the title of a DynaForm in the current process.");
   }
   else {
      PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $formId);
   }
}
or even create a document and send it as an attachment?
Code: Select all
if(@@action == "output"){
   $outputId = "502792749586c9ae036e5e5086358080"; //Set to ID of Output Document
   $fileId = PMFGenerateOutputDocument($outputId);
   if (empty($fileId)) {
      throw new Exception("Error: Unable to generate Output Document.");
   }
   $d = new AppDocument();
   $aFile = $d->Load( $fileId );
   @@outDocUrl = (G::is_https() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . 
      ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'.$_SERVER['SERVER_PORT']) .
      '/sys'. @@SYS_SYS . '/en/neoclassic/cases/cases_ShowOutputDocument?a=' .
      $fileId . '&v='. $aFile['DOC_VERSION'] . '&ext=pdf';
   @@outDocFilename = $aFile['APP_DOC_FILENAME'] .'_'. $aFile['DOC_VERSION'] .'.pdf';
   
   $aFields = array('ownerName' => @=ownerName, 'ownerEmail' => @=ownerEmail, 'endRangeDate' => @=endRangeDate, 'startRangeDate' => @=startRangeDate, 'salesEmail' => @=salesEmail);
   $aAttachFiles = array(
    PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . @@outDocFilename
);
   $usr = userInfo(@@USER_LOGGED);
   $from = $usr['mail']; 
  
   PMFSendMessage(@@APPLICATION, $from, @@ownerEmail, @@salesEmail, '', 'Please Send Me Your Sales Numbers ASAP', 'salesNumbers.html', $aFields, $aAttachFiles);
  
   $formTitle = 'Client Info'; //set to the title of your DynaForm
   $formId = PMFGetDynaformUID($formTitle, @@PROCESS);
   if (empty($formId)) {
      throw new Exception("Error: '$formTitle' is not the title of a DynaForm in the current process.");
   }
   else {
      PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $formId);
   }
}
#788909
Ekaboom, You probably want to start your triggers with code like this:
Code: Select all
if (isset(@@action) and @@action == 'output') {
That way it won't have errors if the user didn't submit the DynaForm.

Also in your trigger to send the output document as an email attachment, you need to use the filename found on the PM server:
$filename = $fileId .'_'. $aFile['DOC_VERSION'] .'.pdf';
Code: Select all
$aAttachFiles = array(
   @@outDocFilename => PATH_DOCUMENT. $g->getPathFromUID(@@APPLICATION) .PATH_SEP. "outdocs" .PATH_SEP. $filename;
); 
You also probably need to send out the email from the user account set in Admin > Email Servers, because most email services (gmail, Yahoo!, hotmail, etc) will block it as spam if it doesn't come from the owner of the account. Your $from should probably not be the currently logged user.
Code: Select all
$from = "admin@example.com";

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]