Page 1 of 1

Create service not adding to database

Posted: Tue Jul 22, 2014 11:54 pm
by Ed Chmiel

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


Create service not adding to database

Posted: Wed Jul 23, 2014 12:22 am
by Ed Chmiel

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.


Create service not adding to database

Posted: Wed Jul 23, 2014 6:24 am
by Kateryna Grynko

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


Create service not adding to database

Posted: Wed Jul 23, 2014 9:11 pm
by Ed Chmiel

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.


Create service not adding to database

Posted: Wed Jul 23, 2014 9:35 pm
by Ed Chmiel

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.


Create service not adding to database

Posted: Wed Jul 23, 2014 9:58 pm
by Ed Chmiel

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.


Create service not adding to database

Posted: Wed Jul 23, 2014 10:00 pm
by Alena Prykhodko

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