SharePoint Asked on November 25, 2021
I have the following code inside my remote event receiver inside a SharePoint online team site, the remote event receiver is deployed inside azure web service:-
if (i["ProjectDateSinged"] != null && properties.ItemEventProperties.AfterProperties.ContainsKey("ProjectDateSinged") && properties.ItemEventProperties.AfterProperties["ProjectDateSinged"] != null)
{
DateTime currentpds = (DateTime)(i["ProjectDateSinged"]);
DateTime afterpds = (DateTime.Parse(properties.ItemEventProperties.AfterProperties["ProjectDateSinged"].ToString()));
if (currentpds.Date != afterpds.Date)
errormessage = errormessage + "You are not authorized to update DateSigned. ";
}
the code is to prevent users from updating a field named ProjectDateSinged… but currently the code is failing because i am getting the same date in different amounts. for example if i have an item with ProjectDateSinged = 15 July 2020
, then the (DateTime)(i["ProjectDateSinged"])
will be equal to 15/07/2020 00:00:00
which is correct, while the (DateTime.Parse(properties.ItemEventProperties.AfterProperties["ProjectDateSinged"].ToString()))
will be equal to 14/07/2020 23:00:00
which is one hour before the correct value, so the validation will always fail.. any advice on how i can fix this?
Thanks
SharePoint stores dates in UTC format. The DateTime returned by AfterProperties["ProjectDateSinged"]
is in UTC format. You will need to convert the DateTime afterpds
to the same format that you are using for DateTime currentpds
and then compare the dates.
Answered by Callum Crowley on November 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP