Can I throw a Signal Event in a Usertask?

Hi!

So in my case I have a form where the User can filter some entries in a list and then should be able to create a pdf, but the only way to create this pdf is to complete the task, following a ServiceTask that creates the pdf based on the former input and then go back to the UserTask with the new Download Link.

Can I instead throw a signal event in javascript that triggers a non-interrupting boundary signal event attached to the Usertask? So the User just needs to click a button ‘create pdf’ and the respective function will trigger the ServiceTask.

Thanks in advance
Alex

@Alexander_S, another option:

Create a separate process something like “Create PDF”. Call this process through JavaScript/Angular inside of your User Task, and have the output of the Create PDF process send the PDF into your active Process.

So in Process A, User Task A, your user will select “Create PDF” button which will call the Process B. Process B will generate the PDF and put the PDF into Process A. Your UserForm A in Process A could self-update every N seconds after pressing Create PDF to look for the file and generate the download link.

(not tested, just an idea)

edit:
Here is a example of call a Camunda Rest API through the embedded form: Loading previous data in process start form

Should be a good start to your problem.

1 Like

Thanks @StephenOTT, that helped me alot.

My solution so far looks like this

$scope.createPDF = function() {

var deployID = "Process_createpdf:5:614c2f5b-684a-11e6-8667-0026c7e5d446";

var optionsforPDF = {"variables":
	{"success" : {"value" : $scope.options.success, "type": "Boolean"},
        "waiting" : {"value" : $scope.options.waiting, "type": "Boolean"},
        "notreturned" : {"value" : $scope.options.notreturned, "type": "Boolean"}},
        "businessKey" : "myBusinessKey"
	}

	$http.post(Uri.appUri('engine://engine/:engine/process-definition/' + deployID + '/start'),optionsforPDF).success(function(data) {

	 var deploymentId = data.id;
	 $http.get(Uri.appUri('engine://engine/:engine/process-instance/' + deploymentId + '/variables/reservationOverview/data')).
                  			 success(function(data) {

		$scope.test2 = data;
                camForm.variableManager.variableValue('reservationOverview',$scope.test2);

										
				 });              	    
                    });
};

But I cannot update the “reservationOverview” variable that is declared in the form in an a-tag as cam-file-download. Even if I use $route.reload(), $timeout, $scope.$apply() or creating a complete new download button and a new Variable with the camForm.variableManager… nothing works.

Any idea how to update the variable and the form so the download link provides the current pdf version?

Just to confirm, you are able to output the URL to console or some other static location? You are sure the download link is being generated, but you cannot update the page with the new URL?

@StephenOTT

I just use the URL within the pdf-creation process B, then I parse the FILE variable to the form in process A.

Here I create the Cam-Variable within the PDF-Creation Task (beforehand I created the pdf with pdfbox):

	FileValue typedFileValue = Variables.fileValue("Reservation_Overview_"+currentd+".pdf")
			.file(new File("../reservationOverview.pdf")).mimeType("application/pdf").encoding("UTF-8").create();

	execution.setVariable("reservationOverview", typedFileValue);

After that I retrieve the variable with the GET-Request as you can see in my previous post. I already checked that I successfully retrieve the variable.

The download link in the Form looks like the following:

<a cam-file-download="reservationOverview"> Download PDF </a>

I wanted to update the ‘revervationOverview’ Variable within the JS of my form in Process A but it seems after the form is build it will not change its value like an angularJS variable would do.

Okay so make sure I understand:

  1. You have confirmed that the url to the file is being successfully stored as a variable in the process?
  2. You are not able to get the url you stored in the variable once it has been set?
  3. Just to confirm: Have you create creating a second user task that allows you to download the file from the url in the variable? Just to confirm that everything is working and the problem is with the form re-load?
  4. Have you tried creating another function to get the variable value? If you do this, does the function return the proper variable value you are looking for?

Edit: When are you calling the execution.setVariable("reservationOverview", typedFileValue); and when do you call getVariable?

@StephenOTT

Sorry I guess there was a misconception. I don’t store the url in a variable, I store the pdf itself in a variable.
I do this in Process B, in the Service Task “create PDF”, through the execution.setVariable - Statement.

I don’t call getVariable, I retrieve this variable through this GET Statement in my javascript in my Process A form:

  $http.get(Uri.appUri('engine://engine/:engine/process-instance/' + deploymentId + '/variables/reservationOverview/data')).
              			 success(function(data) {

	$scope.test2 = data;

      camForm.variableManager.variableValue('reservationOverview',$scope.test2);

With this I retrieve the ‘reservationOverview’ Variable from Process B I just set and then store it to the angular-variable test2. With the last Statement I set the local reservationOverview-Variable from Process A to the just received variable from process B. Problem is that this Part doesn’t work as intended.

The

    <a cam-file-download="reservationOverview"> Download PDF </a>

in the html part is linked to this local variable that has a binary value. This is not an url like you would declare it with a href-Tag.

Problem with this approach is that even if I update the local reservationOverview variable it doesn’t carry over to the form dynamically. It doesn’t recognize that the value has been updated ones the form is loaded.

My question would be if there is the possibility to reload the form or at least some elements of the form? Or would you suggest to use a normal a href=“url” construct? That was my first approach but I couldn’t figure out the correct relative path to the folder where i store it on my tomcat server when calling the download link from withing the camunda tasklist.

For those who might be interested, I found an okay solution for my problem.

$http.get(Uri.appUri('engine://engine/:engine/process-instance/' + deploymentId +   '/variables/reservationOverview/data'), {responseType: 'arraybuffer'}).
                  	 success(function(data) {

	var file = new Blob([data], {type: 'application/pdf'});
        var fileURL = URL.createObjectURL(file);
      	window.open(fileURL);
	 });    

I simply make a FILE object from the data I get from my REST request and open it directly in my browser.

2 Likes