Bonita 7 / Initialize contracts attributes
Hello.
Contracts seem to be the expected way to define how data are exchanged between a process and forms. Operations let handle post-processing, after a form is submitted, and pass back incoming values into process state variables (business objects or just variables).
But I've not found any way to initialize contracts attributes from process variables before a form is call.
Any idea ?
Thanks.
Regards.
Hello @ephemeris.lappis and @yannick.lombardi !
You can initialize a contract input with a UI Designer form as follows.
UI Designer variables -- formOutput | return { 'c_text': $data.varText.value }; | Javascript expression task | ../API/bpm/task/{{taskId}} | External API taskId | id | URL parameter varText | ../API/bpm/caseVariable/{{task.caseId}}/varText | External API Text input configuration -- Value | varText.value
where: - "c_text" is the contract input name - "varText" is the Pool's variable name
Basically use the bpm/caseVariable REST resource to get a Pool's variable value. Then use this variable as a form's widget value.
Hope this helps.
Comments
I'm afraid it doesn't help :(
What you describe seem to force the contract's output field value with the process variable value, and this is actually what it does when the form is submitted, since the input field is ignored...
What I try to do is to set the input field, form the contract, with the process variable, when the form input is initialized before the form is displayed and filled...
Perhaps I've not understood...
@trucngn I try your solution but now I can't edit the content of the "c_text" field. It is initialised with the value from my process variable but when I run the process I can't edit the value in the field. In the UI Designer, I check the "no" box for Read-Only. I don't understand why I can't edit the content of this field.
EDIT : Now it works. I had a javascript error.
Hello.
No, I have still problems to make it work.
I've added this to variables :
mvTask ../API/bpm/task/{{taskId}} External API
And I've tried to use a request field that may have been filled on previous iterations of the same task to initialize the binding of the input widget :
But I have an exception in the logs, that says that the case variable is not found :
org.bonitasoft.web.toolkit.client.common.exception.api.APIException: Error while getting case variable
at org.bonitasoft.web.rest.server.datastore.bpm.cases.CaseVariableDatastore.findById(CaseVariableDatastore.java:117)
Perhaps what you say only work for plain process variable, and not for business objects ? In ly case, "request" is a business object with several attributes, and "answer" is the field that may be given multiple times depending on iterations...
Thanks for you help.
Hello again !
I've changed it with that set of variables, using the context's "request" business object :
formInput {
"answer" : "",
"ok" : false
} JSON
formOutput return { 'answer': $data.myRequest.answer, 'ok': $data.formInput.ok }; Javascript expression
myRequest ../{{context.request_ref.link}} External API
taskId id URL parameter
And the widget is set with :
It seems to work : Yes !
But I'm not very sure I've understood all what is done "under the hood"...
First, the syntax to access the reference of the process business object "variable_ref.link" is not trivial.. Second, at the end of the form, I've an operation that set the "request.answer" with the form's contract "anwser". Is it actually needed, or the value is directly set by the form ?
Thanks for your help.
I'll mark the question as answered !
Hello,
the basic concept is that a task (or a process) is offering a context to the form (read only) and the form is submitting values to a task (or process) contract.
Your form can leverage all the context information and must respect the contract at submission. So far, the context is not extensible. By default, it is exposing the business data and teh documents. We plan in a coming release to make it configurable so that you can add any entry of your choice. From a best practise perspective, make sure you do not put too much process data in the context because it make you loosing most of the added value of this context/contract feature. The idea behind this feature is to ease collaboration between process developers and views developers. Once the contract & context are defined, bot of developers can work on their task and change whatever they want as long as context & contract remain unchanged. Now you easily see that too much process variables breaks this concept because any change during the process development will impact the context and as a consequence break the collaboration.
Hope this helps, Charles
Comments
I have the same problem. I try to initialize a field with my variable by adding the value of my business variable in the json but it doesn't work.
I try this for my formInput :
"businessVariable" : {
"name" : "{{businessVariable.name}}"
}
}
It display {{businessVariable.name}} instead of the value.
I've also tried to set it the same way, and it doesn't work... I've tried to dot it using an intermediary variable set by external API, but the input JSON seems to be evaluated before, and thus no way to get the process variable value to set contracts elements...
No more ideas ? :(