03-15-2017 01:26 AM
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
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
03-15-2017 12:21 PM
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
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:
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.
03-15-2017 12:21 PM
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
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:
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.
03-15-2017 09:43 PM
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
11-12-2019 08:20 PM
Hi, have you solved this problem yet?
Explore our Alfresco products with the links below. Use labels to filter content by product module.