Nov 19 2021 08:38 AM
I'm attempting to use oListItem.set_item to insert date data into SharePoint from a custom form. I keep receiving "Request failed.String was not recognized as a valid DateTime. Essentially the date coming from the format of 2021-09-21 or (YYYY-MM-DD), it needs to be in the form of 09/21/2021(MM/DD/YYYY)
Any help appreciated.
Nov 20 2021 12:15 AM
@mwilliams71 Try using:
var formattedDate = new Date("2021-09-21").toJSON();
OR
var tempDate = new Date("2021-09-21");
var formattedDate = [tempDate.getMonth() + 1, tempDate.getDate(), tempDate.getFullYear()].join('/');
Use formattedDate variable to set the date column using oListItem.set_item().
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Nov 20 2021 07:20 AM
Nov 22 2021 01:23 AM
@mwilliams71 Are those two date fields "Required" in column settings/list settings? If yes, you have to make them optional from list settings.
For empty date fields, you don't have to write ".set_item()" in your code.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Nov 22 2021 10:25 AM
Nov 22 2021 12:43 PM