Update Date Field via Javascript causing an error

Hiya @mnikitina

We are updating a date field from another field, using the following function:
function GetSODetails(Field) {
var SOItemID = Field.LookupId;
pnp.sp.web.lists.getByTitle('Sales Orders').items.getById(SOItemID).get().then(function(item){
fd.field('Due_x0020_Date').value = item.Delivery_x0020_Deadline;
fd.field('Currency').value = item.CurrencyId;
Currency = item.CurrencyId;
});
}

This works as it fills in the correct date, but when you try to save, you get this error:

Please can you help?

Hello @Jamal_Smith-Graham,

You need to convert the date string to the valid date format using a date object. Please see the updated code.

function GetSODetails(Field) {
var SOItemID = Field.LookupId;
pnp.sp.web.lists.getByTitle('Sales Orders').items.getById(SOItemID).get().then(function(item){
// creates a new date object from a date string
var date = new Date(item.Delivery_x0020_Deadline);
fd.field('Due_x0020_Date').value = date;
fd.field('Currency').value = item.CurrencyId;
Currency = item.CurrencyId;
});
}
1 Like

Thanks again!!! :smile:

1 Like