Strange behaviour trying to write Date to customfield using Automation Command

I’ve been playing around and getting familiar with SambaPOS4/5, Trying to prepare a setup for our Bussiness which we hope to open around springtime . A Campsite with also some B&B rooms. (As soon as the Bussiness is Registerd I’ll buy a License :wink: )

To be able to close tickets on customer accounts but still keep track of guests in rooms and/or pitches i’m trying to write Customfields on Rooms.

I’m trying to wite the Current Date to a custom field when a automation command is pressed using report command {DATE}.
The automation command also writes the “Guest” and “NumberGuest” which works fine. But for writing the current date i’m stuck and kind of surprised whats happening.

The Action

The Rules

And an example of the result in the Customfields

The result i would expect to see is the current date: 27-10-2015

The result that’s being written in the Custonfields DateCheckIn and DateCheckOut only sometimes will be displayed in the “Batch Entity Editor” although the other customfields, Guest and NumberGuests will be correctly updated. But there is something written in the Custom field if i take a look in the Database (So this probably just will be a Cache Issue).
If you click on the down arrow next to the Custom Field it will jump to the written date in the Calander and display the written Date.

Now the main issue: The dates being written in the Date field are always lowered by 27 in the first Customfield, the second room does something else but seems to caculate also on the first room for how much the Date value is lowered.
(Edit): Today is the 27th, so is it duducting the amount os days of the current date or previous date???

Some examles of written Date in Excel

Can somebody help me?

  • Am I using the correct format for writing a Date to a custom field or is there a better way to write the Current Date to a Customfield?
  • Should the {DATE} work over here ?
  • Is this behaviour as expected or is it some “Bug”? And if it is as expected what is happening?

Thanks in advance,
Ruth

First thing I would sugest trying is specifying the date format.
Look in this post for date formatting;

Can you show the entity type settings for that field?

This is what it currently is.
I’ve already been trying different settings for Field & Mask type.

I’ve just tried it with DateCheckIn: [=FD(’{DATE}’,‘dd-MM-yyyy’)] in the Rule. But still the same result.

When field type selected as Date it will process dates as it process date inputs on Report Module’s date filter area. So you can use this format but try removing dash (-) characters between date parts and use space character instead.

[=FD(‘{DATE}’,‘dd MM yyyy’)]

3 Likes

That did the trick, now it’s writing the current Date: 27 10 2015.

Thanks alot :smile:

1 Like

@emre just noticed a similar issue in one of my scripts, the json response returns the date in this format;

2015-10-29 10:00:00

How can I format the date within the script before loading into entity data with

api.Entity(roomname).Data(entityField_depart).Update(formatted_depart);

Not unexpectedly this doesn’t work;

var result_depart       = responseObject[roomsiteindex].booking_departure;
var formatted_depart	= [=FD(result_depart,'dd MM yyyy')];

Emre introduced this script function to me for formatting purposes …

var dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

So try something like this:

var formatted_depart = result_depart.ToString("dd MM yyyy");

Thanks, but I get a message saying;

Object doesn’t support this property or method

Ok, it is because the var is not a date object. Look at this (Googled) …

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

The ToString() method applies to DateTime objects, and I believe is a .Net construct, which is what I searched for.

Reducing the code in the link, you might try something like this (not tested)…


EDIT: this is simplified …


// First convert your string into DateTime variable: 
var dt = DateTime.Parse(result_depart);

// Then convert this variable back to string in correct format:
var formatted_depart = dt.ToString("dd-MM-yyyy");

Found similar result suggesting DateTime.Parse(result_arrive)
Now puts date into entity field however think maybe I shouldn’t be using to string as now the entity field doesn’t see it as a date but as string LOL

Yah, dates and strings are funny things. Personally, the return value from JSON is the correct representation of date/time, so IMO, I would leave it like that, but to each their own.

However, even your Regional settings may mess with this in the Custom Data field.

You need to decide what works best for you, converting the format and store as string, or leave it be and store as date, or… lots of options.

Just double checked my regional settings as on my tablet and they were US.
But that doesn’t solve the problem.
How does samba want to receive a date?

As it stand the value retuned by depart_todate.ToString("dd MM yyyy") puts the value as expected into the field but doesn’t look like samba takes it as a date (it doesn’t show in the field until you select it, if I use the date picker it shows the date as expected.

If the format retuned by Json I get completely wrong dates.
26/10/15 ends up as 21/04/10

Hmm… Sorry I think I misguided you because what I was talking about here relates with Ticket Tags that accepts date tags. (Like delivery date).

Custom Field’s date thing does nothing more than just displaying a date picker for editor. In all cases value stored as a string value.

What is happening here is our date expression feature (that adds days to dates) works somehow but by chance it does not work when we use spaces between date parts :slight_smile: I’ll correct it for next (5.1.55) update.

PS: I removed solution flag.

Sorry, so what should I do?
Leave it as sting format as dd MM yyyy with spaces ready for next release?

I’ll tell after solving it :slight_smile: I’m working on it.

2 Likes

Not even going to try and understand that LOL

That is really simple (and amazing). You write code that tests code and it works everytime you create a setup.

1 Like

26/10/15 is not an expected date format returned by a web api. Did you meant 26/10/2015 ?