Copied to clipboard

Flag this post as spam?

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


  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 10:38
    AmandaEly
    0

    Unable to get correct value for TrueFalse property using UmbracoHelper

    I am using 7.2.4

    I realise that I must start using UmbracoHelper to retrieve my rather large amount of data, as the services are slow and in any case, designed for CRUD, not for query.

    So:

    var result = Umbraco.TypedContent(56752); var ispb = result.GetPropertyValue

    var ispbProp = result.GetProperty("ispb");// false as well
    
    var contentService = ApplicationContext.Current.Services.ContentService;
    var contentResult = contentService.GetById(56752);
    var ispbContent = contentResult.GetValue<bool>("ispb"); // true
    

    which makes it impossible to choose all the results which are pbs out of my 6,000 plus (and growing) results unless I use ContentService or start trying sql queries (which I don't fancy at all).

    Currently I use ContentService everywhere and pages take upwards of 10 mins to load. Yesterday I tried every way of inducing the UmbracoHelper to give me the correct result for the id given (or any other Id I know of) but failed. I have 1501 results for which "ispb" is true, I can see that in the cmsPropertyData table.

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 10:56
    AmandaEly
    0

    I just tried another property on this with perfect results:

    var result = Umbraco.TypedContent(56752);

    var age = result.GetPropertyValue<int>("age");
    var ageProp = result.GetProperty("age");
    
    var contentService = ApplicationContext.Current.Services.ContentService;
    var contentResult = contentService.GetById(56752);
    
    var ageContent = contentResult.GetValue<int>("age");
    

    All came out at 60. Strange

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 10:57
    AmandaEly
    0

    var ispbInt = result.GetPropertyValue

    Also gives 0, when using Umbraco "Helper"

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 11:21
    AmandaEly
    0

    var properties = result.Properties;

    on the UmbracoHelper result gives me 13 properties ias XmlPublishedProperty. One of these is "ispb' and is set to false.

    How odd.

    Incidentally, there are three versions of this property for this result in [cmsPropertyData]. One is null, one is 0 and one is 1.

    There are also four versions of the result document. The versionid guid of the most recently saved result document is repeated in the correct property data row.

    So how to I get UmbracoHelper to choose the most recent one? I don't think this is my job as a simple developer of an Umbraco website, C# programmer or no.

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Aug 23, 2015 @ 12:00
    Marc Goodson
    1

    Hi Amanda

    Yes you are right the ContentService is not to be used on the frontend of the website, it interacts directly with the Umbraco database, which is not optimised for querying data and UmbracoHelper is the 'way to go'; or for large numbers of nodes use Examine search.

    When you publish content with Umbraco, the content for the pages is inserted/updated into the Umbraco Xml Cache file, which is just an xml file in app_data/umbraco.config.

    When you use UmbracoHelper it is this XML file in memory that is being queried, which improves the speed of returning the published content.

    You've possibly seen the reference stuff on UmbracoHelper here ? https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    Anyway from what you are typing I think you are already up-to-speed with that...

    So yes your specific thing:

    var result = Umbraco.TypedContent(56752); 
    var ispb = result.GetPropertyValue("ispb");
    

    GetPropertyValue returns an object here - but there is a strongly typed overload so you can write:

    var ispb = result.GetPropertyValue<bool>("ispb");
    

    which should then cast the result to be a true/false boolean value.

    If you are querying for all content with ispb property true you should be able to write something like:

    Umbraco.TypedContentAtRoot().First().Descendants().Where(f => f.IsVisible() && f.HasProperty("ispb") && f.HasValue("ispb") && f.GetPropertyValue<bool>("ispb"));
    

    to return an IEnumerable

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 12:43
    AmandaEly
    0

    Marc,

    Thanks for your reply. Yes, I have tried all that or variants of it. I still get false. I now think it is about the cache being out of date. I have also done "Republish entire website". No difference. Deleted umbraco.config and app data/cache. No difference. I guess I just need to work out which bit of App_data to delete next.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Aug 23, 2015 @ 13:31
    Robert Foster
    0

    Hi Amanda, Can you please post your Document Type showing the property in question (screen shot if you like)...

    Also, after publishing, open up the ~/App_Data/umbraco.config file and search for the node you are expecting the true value on. Sure fire way to know whether the cache is being refreshed properly or not.

    Apart from that, as mentioned previously you should never ever be using ContentService for querying data in the front end - it's okay if you need to update something in response to a user action, but that's pretty much the only time.

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 13:44
    AmandaEly
    0

    screen capture is below

    Yes, I know I shouldn't be using ContentService. I did mention that in the very first part of this thread.

    Here is the entry in umbraco.config

    as you can see, not even the "age" is filled in here, which is strange, as I can access that value via UmbracoHelper.

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 13:48
    AmandaEly
    0

    enter image description here

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Aug 23, 2015 @ 13:58
    Robert Foster
    0

    ok, so, what happens to the cache when you edit another property? Is it updated?

    And can you confirm the value of the property after save and publish that it's still true?

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 14:02
    AmandaEly
    0

    All these docs and their properties were added from a back end project using contentservice. I am moving the data over from a legacy website, which uses php and mysql. The property in question was added after the docs were added, which perhaps explains why there are three versions of one property data entry (although perhaps not).

    As mentioned, I have republished the entire website to no useful effect. I have also deleted the umbraco.config. No change.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Aug 23, 2015 @ 14:10
    Robert Foster
    0

    So are you importing the Race Results? What happens if you un-tick this property and re-tick it? What is the value of the property type when you import it? Is it a bool? An int? This may be the root of your problem if the import isn't converting the property value before assigning it.

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 14:18
    AmandaEly
    0

    Not importing, no. The original database used pretty much flat files. As I said, I am using content service. I created each entry and its properties. Later I calculated which of these results would be counted as "ispb" and ticked the ones which were.

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 14:38
    AmandaEly
    0

    Having said that, perhaps I missed out on how to update the cache/xml files in the website project after using the backend project? How do I update them (aside from republish, which doesn't seem to cut it)?

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Aug 23, 2015 @ 15:14
    Robert Foster
    0

    Ho did you tick the entries? Are you programmatically setting the values, or just using the backoffice UI?

    The only thing I can think of that may be causing this is that the wrong value type is being saved back to the property.

    The other thing you could try is go to the log file in ~/app_data/logs and see if there are any errors reported there when you try to save the document...

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 15:41
    AmandaEly
    0

    I set the values using my back end console application as recommended by (I seem to remember) Jeroen. I set the TrueFalse value to true where appropriate. Since I have 6000 results, I wasn't keen to do this by hand.

    I am constantly stopping and starting the website. I am still running it on my own PC, since it is far too slow for me to release it. My fault, since I was using contentservice to retrieve data. But not wrong to use it to set up the data in the first place.

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 15:21
    AmandaEly
    0

    I have just deleted umbraco.config again and all the ExamineIndexes files. Then run the website again. Still the wrong value for "ispb" when using the UmbracoHelper right one when using contentservices. In fact, even the "age" is not incorrect when using the UmbracoHelper (but not the content service).

    Actually all 13 properties are now marked as hasValue = false

    At my wits' end here. I think it is something simple. Looks like manipulating data using content (and other) service from a separate project has led to problems.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Aug 23, 2015 @ 15:27
    Robert Foster
    0

    Hi Amanda, Try stopping and re-starting the website service. Also, has there been any errors reported in the log file?

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Aug 23, 2015 @ 15:44
    Marc Goodson
    1

    Next hair pulling avoiding step

    Would be to find one race result in the back office content tree

    Open it

    Look on Properties tab - what url does it say it is published under ? Take a note of it's Id

    What is the status of the ispb checkbox property ?

    Check it.

    Save and Publish the node.

    Open up your Umbraco.Config file on disc, find the element with the Id of the race result you have just published, find it's ispb property in the xml, what is the value stored there ?

    If the entity isn't in the xml config cache, there is a different problem to the Umbraco Helper not returning the right value - if it is there, and it is a boolean value, then test UmbracoHelper on that particular NodeId, is the correct value returned using .GetPropertyValue

    If you used Save on the content service when importing the items will not be published in Umbraco.

    Republishing the site, won't cause nodes that have not been published before to become published.

    The content service has a PublishWithStatus method, if you wanted to update the cache after each result import. (but import will take longer)

    Agree you are really close !!

  • AmandaEly 123 posts 379 karma points
    Aug 23, 2015 @ 15:58
    AmandaEly
    0

    Hi Marc,

    I might leave this to tomorrow, as I am in a mess after attempting publish on my resultsrepository. Yes, I will try to publish a known result from the office. I did use publishwithstatus on everything (I think). Actually, I can't swear to that.Certainly most of the time.

    Thanks for encouraging words.

    Amanda

  • AmandaEly 123 posts 379 karma points
    Aug 24, 2015 @ 07:34
    AmandaEly
    0

    Ok, I opened up a known result in the Umbraco back office. This one had pb marked as true. I published this result. Then I used UmbracoHelper to fetch it and find the value of "ispb". It came back true!!! Hooray!

    I can't get too excited about doing this manually on 6000 plus results. Marc, you mentioned publishwithstatus and import. I don't know what import is in this context.

    How about if I use publishwithstatus on each result? I'd do this with contentservice in the console application I have been using to put data into Umbraco.

    Amanda

  • AmandaEly 123 posts 379 karma points
    Aug 24, 2015 @ 08:16
    AmandaEly
    101

    I have now called the Umbraco/dialogs/republish.aspx?xml=true. This has given me 1335 results with ispb=true. I have to say this is a massive improvement, although not perfect, as I know (via contentservice) that there are, in fact, 1500. Never mind for now, that will do.

    Thanks people!

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Aug 28, 2015 @ 10:02
    Marc Goodson
    1

    Hooray!

    Yes so I think the issue was that the ispb value is set correctly in the Umbraco Database, but wasn't published to the Umbraco.config xml file.

    The contentservice has PublishWithStatus method that should save to the database and publish to the config file, for each item. So it's possible that when you set the isPB values, you just used Save, which only saved them to the database.

    (sometimes this is prefererable, than causing the publish to happen 2000 times during an import)

Please Sign in or register to post replies

Write your reply to:

Draft