Popup Confirmation Dialgue in Alfresco Activiti

cancel
Showing results for 
Search instead for 
Did you mean: 
jeenut
Active Member

Popup Confirmation Dialgue in Alfresco Activiti

Jump to solution

I am using a Activiti Enterprise edition and I want a popup feature to appear on submission of the start form. For attaining this I added the following Javascript to Javascript tab in the form to the form control 

if (execution.getVariable("adhocflag")== true){
   var wrongdateflag;
   var txt;
   var r = confirm("A review for this Review Period date already exists. Do you wish to continue?");
   if (r == true) {
      console.log("You pressed OK!")
   } else {
      console.log("You pressed Cancel!")
      return false;
   }
}

Basically, I want to access an existing execution variable in the function. But I am not able to achieve this. Also I want to get access to a variable declared in the same form. Can someone explain how this can be achieved?

Am I missing something here??

Regards,

Jeenu

1 Solution

Accepted Solutions
jearles
Established Member II

Re: Popup Confirmation Dialgue in Alfresco Activiti

Jump to solution

Jeenu,

So you don't have access to the execution variables using the same methods that you would in something like a script block, however, they are still entirely available to you - and you're basically doing all the right things except for that Smiley Happy

Note how when you're using the 'formRendered' function, you have access to form & scope; there isn't a ton of documentation on this, so I like to console.log(scope) and then explore the data and functions I have access too. Anyway, within scope you have a function called findFormFieldWithId(e, t) - you'll be able to use this to acquire the variable value you're looking for. The first value to the function should be a scope of variables, of which I found two available in the scope:

  • scope.currentAndHistoricFormFields
  • scope.allFormFields

Contrary to what you might guess, I found the 'currentAndHistoricFormFields' to contain what I was looking for, but depending on where you're setting the "adhocflag" it could be in either (or both). Play around with that to see how Activiti scopes variables inside of 'scope'.

scope.findFormFieldWithId(scope.currentAndHistoricFormFields, 'adhocflag')); << Finds the object value of adhocflag

Within that object, look for fields like .type/.id/.name and then find the one that suit your use case.

So you should be able to do (or something like it):

if (scope.findFormFieldWithId(scope.currentAndHistoricFormFields, 'adhocflag')).value != null){
   var wrongdateflag;
   var txt;
   var r = confirm("A review for this Review Period date already exists. Do you wish to continue?");
   if (r == true) {
      console.log("You pressed OK!")
   } else {
      console.log("You pressed Cancel!")
      return false;
   }
}

For context about what I did for setting variables, I just ran a:
execution.setVariable("adhocflag", "this is a value");
in a script task prior to the form I was messing with.

Hope this helps,
-JEarles

View solution in original post

3 Replies
jearles
Established Member II

Re: Popup Confirmation Dialgue in Alfresco Activiti

Jump to solution

Jeenu,

So you don't have access to the execution variables using the same methods that you would in something like a script block, however, they are still entirely available to you - and you're basically doing all the right things except for that Smiley Happy

Note how when you're using the 'formRendered' function, you have access to form & scope; there isn't a ton of documentation on this, so I like to console.log(scope) and then explore the data and functions I have access too. Anyway, within scope you have a function called findFormFieldWithId(e, t) - you'll be able to use this to acquire the variable value you're looking for. The first value to the function should be a scope of variables, of which I found two available in the scope:

  • scope.currentAndHistoricFormFields
  • scope.allFormFields

Contrary to what you might guess, I found the 'currentAndHistoricFormFields' to contain what I was looking for, but depending on where you're setting the "adhocflag" it could be in either (or both). Play around with that to see how Activiti scopes variables inside of 'scope'.

scope.findFormFieldWithId(scope.currentAndHistoricFormFields, 'adhocflag')); << Finds the object value of adhocflag

Within that object, look for fields like .type/.id/.name and then find the one that suit your use case.

So you should be able to do (or something like it):

if (scope.findFormFieldWithId(scope.currentAndHistoricFormFields, 'adhocflag')).value != null){
   var wrongdateflag;
   var txt;
   var r = confirm("A review for this Review Period date already exists. Do you wish to continue?");
   if (r == true) {
      console.log("You pressed OK!")
   } else {
      console.log("You pressed Cancel!")
      return false;
   }
}

For context about what I did for setting variables, I just ran a:
execution.setVariable("adhocflag", "this is a value");
in a script task prior to the form I was messing with.

Hope this helps,
-JEarles

jeenut
Active Member

Re: Popup Confirmation Dialgue in Alfresco Activiti

Jump to solution

Hi Jonathan,

Thank you for the reply. I was able to access a form field in the JavaScript following the explanation you provided. 

But when I need to access a execution variable that was declared elsewhere like in a service task, the script is not able to do so. What do I do in such a situations?

Regards,

Jeenu

longlong
Member II

Re: Popup Confirmation Dialgue in Alfresco Activiti

Jump to solution

Hi, have you solved this problem yet?