Question

I have the following code inside my remote event recevier, to assing a value for a Date Time field, as follow:-

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
  using (ClientContext context = Helpers.GetAppOnlyContext(siteUrl))
            {
          if (properties.ItemEventProperties.AfterProperties["ProjectApproveDelay"] != null && properties.ItemEventProperties.AfterProperties["ProjectApproveDelay"].ToString().ToLower() == "yes" )
             {
               result.ChangedItemProperties.Add("ProjectEstimatedCompletionCurren0", DateTime.Now);         
             }

but this will return the following error:-

Invalid date/time value. A date/time field contains invalid data. Please check the value and try again.

although both the server hosing the remove event receiver + the site collection follow the UK time standard. and the DateTime.Now will be something as follow 27/01/2020 23:01:32

Was it helpful?

Solution

In SharePoint, Date and Time Field takes date in ISO Format.

So, try converting date-time value in ISO format and then use it.

Try below solutions:

  1. Converting to ISO Format:

    DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");

    Given a DateTime object, how do I get an ISO 8601 date in string format?

  2. Try using Invariant Date Format:

    DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);

    SharePoint: Assigning values to DateTime fields.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top