This project has moved and is read-only. For the latest updates, please go here.

SPutility.SetValue from variable

Jan 22, 2015 at 8:44 AM
Hi,
I have date field and I need to save its value and then set its value back. But this code is not working:

var DateField = SPUtility.GetSPField('Date');
var DateValue = DateField.GetValue();
DateField.SetValue(DateValue);

How can I achieve that?
Jan 25, 2015 at 6:59 PM
Take a look at the documentation for Date and Time fields.

Assuming your field is a date only field, something like this should work for you:
var DateField = SPUtility.GetSPField('Date');
var DateValue = DateField.GetValue();
DateField.SetValue(DateValue.Year, DateValue.Month, DateValue.Day);
If it is a date AND time field, then something like this:
var DateField = SPUtility.GetSPField('Date');
var DateValue = DateField.GetValue();
DateField.SetValue(DateValue.Year, DateValue.Month, DateValue.Day, DateValue.Hour, DateValue.Minute);
Hopefully this helps! Thanks,
Kit
Marked as answer by jurekk on 1/26/2015 at 5:59 AM
Jan 26, 2015 at 1:59 PM
works great, thank you!