Ng-model for java.util.Date in a struct

Hi there, I want to edit about 90 values belonging to the same business object. So, I decided not to use a Camunda variable for each of this 90 values, but to have one variable and use the attribute “ng-model” instead of “cam-variable-name”. This works pretty fine with one exception: for Dates, there is not the date visible, but a strange number instead.

When I take a look at the variable in the cockpit, I can select between two tabs entitled “serialized” and “deserialized”. On the “serialized” tab, I can see this number. On the “deserialized” tab, I can see the valid date.

So the question is: how can I deserialize to use the Date in the input control?

Hi @cjacob,

The Number is probably a unix timestamp. You can try to parse it to a JS Date Object (new Date(<your variable>)).

If this does not work, please post one of the numbers you receive :slight_smile:

Hi Martin, some questions:

  • where should I parse? In variables-fetched or form-loaded? into what?
  • what is a “JSDate”? I do not have any knowledge about scripting languages…

The field is question is an element of a Java class. The element is of type java.util.Date.

Here you can see how it is presented in the form:

If you look at the variable from the cockpit, its serialized value looks like this:

And this is how it looks on the deserialized tab:

I’m already thinking about using a plain Java String instead of java.util.Date. Any other idea?

in the meantime, I found some more interesting things.

First, I added the following lines to the ‘variables-fetched’ script:

		var unix_ts = $scope.me.angebotsdatum;
		$scope.me.angebotsdatum = new Date (unix_ts);

(“me” is the variable name of my root object)

When I used the Chrome debugger, I could see that this worked fine.

The code in the form is:

	<input type="text" 
		ng-model="me.angebotsdatum"
		class="form-control"
		cam-variable-type="Date"
		required/>

The form now displays it this way:
Form

This is of course better than in my first screenshot, but still not as expected.

Hi @cjacob,

the Data fetched by forms is unserialized by default (source). You can either fetch the variable manually from this REST Endpoint or use another HTML input element with the raw value, such as datetime-local.

Angular’s datetime-local helped out. And it is pretty nice.