Copied to clipboard

Flag this post as spam?

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


  • David 57 posts 80 karma points
    Jun 12, 2010 @ 15:35
    David
    0

    Action Handler to handle "create" action

    I'm having a bit of an issue which is probably more related to my C#/.Net comprehension or lack there of.   In my class Execution() method I'm attempting to test when a specific document Alias is created.   Then based on that check a property on the parent page and set a property on the newly created page based on that.   More specfically....... I have a true/false option on the parent, if its set to true I want to set the child true/false option to true.  

    I'm having trouble getting the value of the parent true/false.   So far I have this.............

                if (action.Alias != "create") return true;

                if (documentObject.ContentType.Alias != "ChildPage") return true;

                if (string.Compare(documentObject.ContentType.Alias, "ChildPage", true) == 0)

                {

                    umbraco.cms.businesslogic.web.Document parentDocument = new umbraco.cms.businesslogic.web.Document(documentObject.Parent.Id);

                    if (parentDocument != null && parentDocument.Id > 0)

                    {

                        umbraco.cms.businesslogic.property.Property p1 = documentObject.getProperty("ParentTrueFalse");

     //Here is my stumbling block - how do I get the p1 value of the true false?  if I add .Value.ToString() to the line above before the; 

                     // I get "Cannot implicitly convert type 'string' to 'umbraco.cms.businesslogic.property.Property' 

                    }

                }

     

    Obviously I'm not completely understanding yet of all the intricacies of .Net - can anyone help get me going in the right direction? 

     

    Thanks

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jun 12, 2010 @ 21:18
    Tim
    0

    Hiya,

    You can pull the property out as a string like this:

    string test = documentObject.getProperty("ParentTrueFalse").Value.ToString();

    You can then check to see if the value is "0" or "1" if it's a true false checkbox data type.

    In your code, you were pulling it out as a property, which is why you got the error when you tried to turn it into a string!

    Hope that helps!

    :)

  • David 57 posts 80 karma points
    Jun 14, 2010 @ 15:22
    David
    0

    No matter what I try 

    if (test = "1")  

    { }

    or 

    if (test = 1)

    { }

    I continue to get "Cannot implicity convert type 'string' to 'bool' " and  "Cannot implicity convert type 'int' to 'string' "  Must be something I'm missing, I'll keep plugging away at it.  Thanks for the tip.  

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jun 14, 2010 @ 15:33
    Morten Bock
    0

    You need to == signs to do a comparison:

    if(test == "1")

  • David 57 posts 80 karma points
    Jun 14, 2010 @ 15:45
    David
    0

    Thanks, I feel like a tool now.  I know I tried that previously with no luck, but I must have gotten the syntax incorrect.   Anyway........thanks.  

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jun 16, 2010 @ 01:44
    Tim
    0

    D'oh, sorry, missed out an = on my code, sorry!

Please Sign in or register to post replies

Write your reply to:

Draft