Creating page with Content Service with custom CreateDate not working?
Hi!
I'm currently building a social feed import which imports instagram data and media.
Everything works fine for custom properties, but I always get the import date instead of my custom date.
Hi Sean,
CreateDate and UpdateDate are system fields and shouldn't be assigned to (CreateDate is internally set to the current Date/Time when the content item is created) - treat it as internal use only, and use your own custom property for anything to do with sorting/filtering/viewing the imported create date instead.
Publish At (ReleaseDate) is used to specify a date/time that you want a Content item to be published using Umbracos' built in task scheduler, so that's not going to help you at all.
If I was to write a script to migrate a news section I would always need to write to a custom property? Or do people usually write directly to database for migration? Why shouldn't system fields be writable, at least by developers, performance or stability issues?
...
A bit off topic, how would I write a sort by with a fallback? I've tried google, but my lingo is probably off because I can't get any matches.
Never write to the database - lots of potential problems ensue :)
Generally, the only field you shouldn't need to add is the Name (and many people add an alternative PageTitle or something similar anyway).
If you're dealing with pre-existing data that includes things like create date or anything else, you'll need a custom property.
My standard Article Document Type for example always includes a "Post Date" property so I can set the date I want the post to appear to have been created on specifically.
As for ordering, the default order is the order in which the Document is created - so if you sort your import data by your desired property prior to importing, that should handle it for you.
For sorting on the fly once you've imported, just sort on your preferred field only, forget the CreateDate...
So your require your editors to set the Post Date for new articles as well?
I'm with you on leaving CreateDate alone , but I want to use it as a fallback for when there is no need for the editor to enter current date.
But I can't just get the SortBy right as described above.
With the Post Date I automatically set it by hooking into the Save/Publish events - however, I have it set up so that the Editor has the option of changing it:
My preference is to use standard LINQ wherever possible, so I don't normally use Dynamics for this kind of stuff (or do it on a Controller/Helper class so I don't have to expose the business logic in the View) - from what you're doing above (using OrderBy("")) it looks like you're using dynamics, but I could be wrong.
Could you please post a bit more of a code snippet so we have some context on the children variable? And are you doing this in the View, or a compiled dll somewhere?
Nice, thanks for the example code and all your help!
You're right, I was using dynamics.
I switched to typed instead of dynamic so I could use LINQ/Lambda, don't know if possible with dynamics - I gave up finding something useful.
Creating page with Content Service with custom CreateDate not working?
Hi!
I'm currently building a social feed import which imports instagram data and media.
Everything works fine for custom properties, but I always get the import date instead of my custom date.
o_created
gets the right date.CreateDate
gets the date of the import to Umbraco.Should I use SetValue for CreateDate instead, or I'm doing something wrong here? Maybe I should use
publish at
instead?Thanks for any help!
Hi Sean,
CreateDate
andUpdateDate
are system fields and shouldn't be assigned to (CreateDate
is internally set to the current Date/Time when the content item is created) - treat it as internal use only, and use your own custom property for anything to do with sorting/filtering/viewing the imported create date instead.Publish At (
ReleaseDate
) is used to specify a date/time that you want a Content item to be published using Umbracos' built in task scheduler, so that's not going to help you at all.Thanks for your reply!
If I was to write a script to migrate a news section I would always need to write to a custom property? Or do people usually write directly to database for migration? Why shouldn't system fields be writable, at least by developers, performance or stability issues?
...
A bit off topic, how would I write a sort by with a fallback? I've tried google, but my lingo is probably off because I can't get any matches.
Code for sorting:
Only seems to order them by group. Results in the following order:
But I would like it to be:
Thanks!
Never write to the database - lots of potential problems ensue :)
Generally, the only field you shouldn't need to add is the Name (and many people add an alternative PageTitle or something similar anyway).
If you're dealing with pre-existing data that includes things like create date or anything else, you'll need a custom property.
My standard Article Document Type for example always includes a "Post Date" property so I can set the date I want the post to appear to have been created on specifically.
As for ordering, the default order is the order in which the Document is created - so if you sort your import data by your desired property prior to importing, that should handle it for you.
For sorting on the fly once you've imported, just sort on your preferred field only, forget the CreateDate...
Hope this helps...
Rob.
So your require your editors to set the Post Date for new articles as well?
I'm with you on leaving CreateDate alone , but I want to use it as a fallback for when there is no need for the editor to enter current date. But I can't just get the SortBy right as described above.
Thanks
Sean
With the Post Date I automatically set it by hooking into the Save/Publish events - however, I have it set up so that the Editor has the option of changing it:
https://our.umbraco.org/documentation/Reference/Events/application-startup
My code for that might look like this for example:
Anyway, back to the SortBy...
My preference is to use standard LINQ wherever possible, so I don't normally use Dynamics for this kind of stuff (or do it on a Controller/Helper class so I don't have to expose the business logic in the View) - from what you're doing above (using OrderBy("")) it looks like you're using dynamics, but I could be wrong.
Could you please post a bit more of a code snippet so we have some context on the children variable? And are you doing this in the View, or a compiled dll somewhere?
Nice, thanks for the example code and all your help!
You're right, I was using dynamics.
I switched to typed instead of dynamic so I could use LINQ/Lambda, don't know if possible with dynamics - I gave up finding something useful.
Anyway this is LINQ code for date fallback:
Btw my snippet to fetch children (this was done in a partial view):
Million thanks!
is working on a reply...