ContentService.GetValue<DateTime>() not returning saved value.
Hello,
Umbraco version 8.9.1
I'm creating a scheduled task component that needs to 'Move' a node based on a DateTime property on the page set by the editor. i.e. a sort of 'move to archive folder after this date & time' thing.
On the node, I have this property...
with the date and time set. It displays this value correctly if I render it to a razor page.
However, in the component, when I try get the value for this property using the ContentService, it returns the default DateTime value as follows...
Here is the block of code in my component that is used to retrieve the content...
public override bool PerformRun()
{
long totalRecords = 0;
var newsAndEventsDocType = _contentTypeService.Get("newsAndEvents");
var newsAndEventPages = _contentService.GetPagedOfType(newsAndEventsDocType.Id, 0, 999, out totalRecords, null);
if (totalRecords == 0)
return true;
totalRecords = 0;
foreach (var newsAndEventPage in newsAndEventPages)
{
var articles = _contentService.GetPagedChildren(newsAndEventPage.Id, 0, 999, out totalRecords);
if (totalRecords > 0)
{
foreach (var item in articles)
{
if (item.HasProperty("archiveDate")) //returns true
{
var page = _contentService.GetById(item.Id);
var dateValueContent = page.GetValue<DateTime>("archiveDate"); // always returns 0001/01/01 00:00 !!
if (dateValueContent > DateTime.MinValue && dateValueContent <= DateTime.Now)
{
_logger.Info<ArchiveArticles>("This article is about to be moved to Archive: {0}", item.Name);
}
}
}
}
}
return true;
}
I checked other properties with DateTime types on the same page, and they too return default DateTime.Min value.
Can anyone confirm that this is the correct way of doing this, or is there another way that works?
ContentService.GetValue<DateTime>() not returning saved value.
Hello,
Umbraco version 8.9.1
I'm creating a scheduled task component that needs to 'Move' a node based on a DateTime property on the page set by the editor. i.e. a sort of 'move to archive folder after this date & time' thing.
On the node, I have this property...
with the date and time set. It displays this value correctly if I render it to a razor page.
However, in the component, when I try get the value for this property using the ContentService, it returns the default DateTime value as follows...
Here is the block of code in my component that is used to retrieve the content...
I checked other properties with DateTime types on the same page, and they too return default DateTime.Min value. Can anyone confirm that this is the correct way of doing this, or is there another way that works?
Thank you!
is working on a reply...