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)
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.
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
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!
:)
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.
You need to == signs to do a comparison:
if(test == "1")
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.
D'oh, sorry, missed out an = on my code, sorry!
is working on a reply...