Ed Chmiel
Posts: 0
Joined: Fri Jun 27, 2014 11:58 pm

Create service not adding to database

I have a create service that has two events - success and error. I was getting an error because I had the date formatted wrong, and I have an alert in the error handler so I can see if there is any error. Once the date format was corrected, there is no error, but nothing gets added to the database. The mapping to the create service is below. The success simply reposts the query, and I refreshed the collection, and the new record is not there.

Any help appreciated.

Image

Ed Chmiel
Posts: 0
Joined: Fri Jun 27, 2014 11:58 pm

Create service not adding to database

I believe the problem might be in the date. Somehow my error JS got deleted, so indeed, there is an error still in the date. The date JS is:

var dt = $.datepicker.formatDate( "yyyy-mm-dd", new Date(value) );
alert(JSON.stringify(dt));
return $.datepicker.formatDate( "yyyy-mm-dd", new Date(value) );

I see NaN's in the alert, and a complaint about the date to the database. What exactly is the right JS? Thanks.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Create service not adding to database

Hi Ed,

Please use:pre$.datepicker.formatDate( "yy-mm-dd", new Date(value) );/preInstead of:pre$.datepicker.formatDate( "yyyy-mm-dd", new Date(value) );/pre

Ed Chmiel
Posts: 0
Joined: Fri Jun 27, 2014 11:58 pm

Create service not adding to database

Its still not correct.

Image

Either with your code or mine, the alert shows NaN's and the database complains with t he above message. Should it not be yyyy (not yy)? I think something else is wrong.
Thanks.

Ed Chmiel
Posts: 0
Joined: Fri Jun 27, 2014 11:58 pm

Create service not adding to database

Ah, I found it. I was mapping incorrectly. I was mapping "date format" instead of "Date Value"; Presto, it worked, but do note your first response is incorrect, it needs to be yyyy-mm-dd.

Ed Chmiel
Posts: 0
Joined: Fri Jun 27, 2014 11:58 pm

Create service not adding to database

My bad - the first answer is partially correct. When all is said and done, the correct JS to enter into a date column in the database is:

var dt = $.datepicker.formatDate( "yy-mm-dd", new Date(value) );
dt = dt + " 00:00:00.000";
alert(dt); // you can comment this out
return dt;

It works perfectly and stores a date as a date in the database.

For those reading this, don't forget to check you are mapping Value not Format.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Create service not adding to database

Great that you have managed with this! Thank you for update.

Return to “Issues”