I will try to explain what I did to find out the issue in your application and how to solve it.
So first I open your process and took a look at your process instantiation contract. I can find that a complex contract input is defined (named “travelRequestInput”) and this complex input has three attributes that seems related to the data you report not being stored in the database: numberOfNights, perdiem and totalAmount.
Next I checked the business variable. One business variable is declared in the process (named “travelRequest”) of type “TravelRequest”. The default of this business variable is set mostly (except “userId” and “status”) using the contract input including numberOfNights, perdiem and totalAmount attributes.
I also took a look at BDM definition to make sure that attributes names are correct (i.e. match what is used in the default value) and what data type are used.
So far everything seems correct.
So next step is to take a look at the form. Instead of digging in the form I just try to run the process and submit the instantiation form. Submitting the form trigger a REST API call (i.e. an HTTP request) from the user web browser to the Bonita server. Using the web developer tools of the web browser (usually open with F12 key shortcut) we can find in the “network” tab the request being sent asking the engine to create a new instance of the process and providing data as part of the request payload (using JavaScript Object Notation - JSON).
So I submit the process an in the POST HTTP request to http://localhost:45789/bonita/portal/resource/process/LocalTravel%20Request/1.0/API/bpm/process/7763908911897244584/instantiation
I get the following JSON:
{"travelRequestInput":
{"departureDate":"2019-05-07T00:00:00.000Z",
"numberOfNights":0,
"fullname":"testNameInFull",
"hotelNeeded":true,
"origin":"Grenoble",
"destination":"Paris",
"reason":"testReason",
"supervisorName":"testSupervisorName",
"supervisorEmail":"test.supervisor@email.com",
"perdiem":0,
"totalAmount":0
},
"numberOfNights":3,
"perdiem":5}
This JSON represent an object with 3 attributes:
-
travelRequestInput, type: object, value:
{“departureDate":“2019-05-07T00:00:00.000Z”,“numberOfNights”:0,“fullname”:“testNameInFull”,“hotelNeeded”:true,“origin”:“Grenoble”,“destination”:“Paris”,“reason”:“testReason”,“supervisorName”:“testSupervisorName”,“supervisorEmail”:"test.supervisor@email.com”,“perdiem”:0,“totalAmount”:0}
-
numberOfNights, type: number, value: 3
-
perdiem, type: number, value: 5
We can see that the travelRequestInput object has itself three attributes: numberOfNights, perdiem and totalAmount all with a value of 0.
So here we have a first part of the issue. We have duplication for numberOfNights and perdiem attributes. Moreover the actual value is not in the JSON structure that match the instantiation contract defined in the process but in some extra attributes that will be ignore by Bonita.
Now let’s edit the form in the UI Designer. The property “Data sent on click” of the submit button define which JavaScript variable (object) will be used to create the JSON value sent when the button is clicked.
You defined a variable named “formOutput” associated with the submit button. This variable is initialize with the following JavaScript:
return {
'travelRequestInput': $data.formInput.travelRequestInput,
'numberOfNights': $data.numberOfNights,
'perdiem': $data.perdiem,
'totalAmount': $data.PerdiemCalculateDays.value
};
So here we can already fix issue for numberOfNights and perdiem and do a first part of the work for totalAmount: just remove them from the script and only keep:
return {
'travelRequestInput': $data.formInput.travelRequestInput
};
And update the widgets for numberOfNights and perdiem to update formInput.travelRequestInput.numberOfNights and formInput.travelRequestInput.perdiem (instead of numberOfNights and perdiem variables, and delete those useless variables).
If you run the process at this stage (after saving the form) you should have correct data for numberOfNights and perdiem. Now let’s fix the totalAmount.
Add the following statement in the “PerdiemCalculateDays” variable JavaScript initialization code (before the return): $data.formInput.travelRequestInput.totalAmount = CalculateAmount
and also update the references to numberOfNights and perdiem:
var CalculateAmount = Number($data.formInput.travelRequestInput.perdiem) * Number($data.formInput.travelRequestInput.numberOfNights);
And update the widget “Total amount” to use formInput.travelRequestInput.totalAmount
for the value.
And that should be it!