1

I had Column "StartDate" with "Date and Time Format" DateOnly and "Display Format" Display.

And I am using JSOM with OTB to save information to SharePoint list. When I use oListItem.set_item('StartDate',TempStartDateValue) I am getting error:

Request Failed. String was not recognized as a valid datetime

Can anyone help me to solve this?

var TempStartDateValue=document.getElementById("txtCertificationDate").value;
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('TempSec2');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    *oListItem.set_item('StartDate',TempStartDateValue);*
    oListItem.update();
1
  • 3
    The error seems pretty self explanatory. Commented Mar 15, 2018 at 18:40

2 Answers 2

0

We can't update DateTime column with Null values. You need to validate if given value is null or not. If it's not then only update the list item.

if(TempStartDateValue!="")
{
    oListItem.set_item('StartDate',TempStartDateValue);
}
0
var TempStartDateValue=null;
if(document.getElementById("txtCertificationDate").value){
 TempStartDateValue=document.getElementById("txtCertificationDate").value;
}

var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('TempSec2');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
*oListItem.set_item('StartDate',TempStartDateValue);*
oListItem.update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.