Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jay Dobson 75 posts 121 karma points
    Mar 17, 2011 @ 19:55
    Jay Dobson
    0

    Can't Retrieve "Remove At" date from API

    Hi All,

    I'm trying to retrieve the Remove At date from within the Umbraco API.  It returns DateTime.MinValue every time, even if a node does have a Remove At date associated with it.

    I don't see any other properties for the Document object that I could use instead.

    Any ideas?

    Thanks,

    Jay

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 17, 2011 @ 20:05
    Tom Fulton
    0

    Hi Jay,

    How are you trying to access this?

    yourDoc.ExpireDate should do the trick

    Thanks,
    Tom

  • Jay Dobson 75 posts 121 karma points
    Mar 17, 2011 @ 20:20
    Jay Dobson
    0

    Wow, might have helped if I put the code in my original post. ;) 

    That is the field I'm using, but it's coming back as DateTime.MinValue's value every time, which is 0001/01/01 I believe.

    posting.ID = Convert.ToInt32(childDoc.Id.ToString());
    posting.Title = childDoc.getProperty("positionTitle").Value.ToString();
    posting.Location = childDoc.getProperty("location").Value.ToString();
    posting.ReportsTo = childDoc.getProperty("reportsTo").Value.ToString();
    posting.JobStatus = childDoc.getProperty("jobStatus").Value.ToString();
    posting.Category = umbraco.library.GetPreValueAsString(Convert.ToInt32(childDoc.getProperty("category").Value.ToString()));
                           
    posting.UpdateDate = childDoc.UpdateDate;                       
    posting.ExpireDate = childDoc.ExpireDate;   

    Everything else is pulling correctly except ExpireDate.  I've saved, and re-published the doc that does have the Remove At date set.  I shouldn't need to do anything else with it, correct?

    Thanks,

    Jay

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 17, 2011 @ 20:27
    Tom Fulton
    0

    Strange...what version of Umbraco are you using?  I tested here on one of the 4.7 nightlies and it pulls the ExpireDate correctly.  I do get DateTime.MinValue when I don't have it set, but after setting and saving and re-loading the page it comes in correctly.

  • Jay Dobson 75 posts 121 karma points
    Mar 17, 2011 @ 20:37
    Jay Dobson
    0

    I'm using v4.6.1.  I just tried it on another node and same result: Jan 1, 0001.

    I also deleted umbraco.config, recycled the app pools, etc., just to see if there was some sort of caching going on and no dice.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 17, 2011 @ 21:01
    Tom Fulton
    0

    Weird!  Tested here on 4.6.1 and seems to be working fine. Hmmm...

  • Jay Dobson 75 posts 121 karma points
    Mar 17, 2011 @ 21:05
    Jay Dobson
    0

    I'll keep poking around and see what I can come up with.  At least I know I'm pulling the right field.

    Thanks :)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 20, 2011 @ 16:29
    Bo Damgaard Mortensen
    0

    Jay,

    What exactly does the ExpireDate property return? null?

    And.. have you checked to see if the value is actually stored in the database? Just to make sure, really :-)

  • Jay Dobson 75 posts 121 karma points
    Mar 20, 2011 @ 17:08
    Jay Dobson
    0

    No, regardless of whether it is set or not it returns 01/01/2001, which I checked and seems to match-up with DateTime.Minvalue.

    Also, I didn't check the database *holding head in shame*.  cmsDocument table?  Getting the newest record for that node and expireDate is NULL.  The interface is aware of the date even though it's not in the DB.  Is there any reason it's not saving?

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 20, 2011 @ 17:34
    Bo Damgaard Mortensen
    1

    Hi Jay,

    I know this is totally weird and doesn't seem to make any sense, but please try the following:

    posting.ID = Convert.ToInt32(childDoc.Id.ToString());
    posting
    .Title = childDoc.getProperty("positionTitle").Value.ToString();
    posting
    .Location = childDoc.getProperty("location").Value.ToString();
    posting
    .ReportsTo = childDoc.getProperty("reportsTo").Value.ToString();
    posting
    .JobStatus = childDoc.getProperty("jobStatus").Value.ToString();
    posting
    .Category = umbraco.library.GetPreValueAsString(Convert.ToInt32(childDoc.getProperty("category").Value.ToString()));
                           
    Document doc = new Document(childDoc.id);

    posting
    .UpdateDate = childDoc.UpdateDate;                        
    posting
    .ExpireDate = doc.ExpireDate;

    Just to see if it gives you the right output :-)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 20, 2011 @ 17:36
    Bo Damgaard Mortensen
    0

    Or maybe just write out the doc.ExpireDate.ToShortDateTimeString(); to a label or something if you can - just to make sure not messing up any references ;-)

  • Jay Dobson 75 posts 121 karma points
    Mar 20, 2011 @ 17:47
    Jay Dobson
    0

    Bah, I meant to mark your second-last post as the answer.  Either way, you got it.  How the heck did you figure that one out?

    When I iterate through doc.Children is it just loading certain fields on the child nodes with data (for db efficiency perhaps?), but a direct call to a node using an ID actually fully loads the data?.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 20, 2011 @ 17:53
    Bo Damgaard Mortensen
    0

    Hi Jay,

    I can't remember how I figured that out to be honest - I think it was just an experiment I made a while ago after pulling my hair for a good four hours ;-)

    Also, I can't tell you why exactly it doesn't load the full data, maybe you're right about db effeciency.. I don't know!

    However, I would like to know why it is like that - and also if it's a problem to do it that way. Maybe some MVP/Core person could shed some light on this for us? :-)

    All the best,

    Bo

Please Sign in or register to post replies

Write your reply to:

Draft