Testalert.cshtml(14): error CS1061: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'GetPropertyValue' and no extension method 'GetPropertyValue' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference?)
Well, it is sort of embarrassing :) Earlier on, I made a Response.Write to output the value of the variable Projects, to the screen, but in the latest version it just spits out an e-mail, and no output on the screen.
It seems though, I cannot use the GetPropertyValue(var) in this version of Umbraco, but only GetProperty(var).Value.
Numeric selection
I am trying to get all the pages with two numeric properties, where the one is greater than the other, like this:
var Node = @Model.NodeById(1157);
foreach (var page in Node.Children.Where("Visible").Where("maal.AsInt() > opnaaet.AsInt()"))
I does not return any result though, even though maal has a value of 100000 and opnaaet has a value of 2000. If I change the selection to:
foreach (var page in Node.Children.Where("Visible").Where("maal.AsInt() > 2000"))
I get the results needed, but it is not an option to make the selection like this.
What am I doing wrong?
It is probably because you where statement cannot get parsed by the engine.
You are using the dynamic object Model. Try using the strongly typed DynamicNode
Like this :
@using umbraco.MacroEngines @inherits DynamicNodeContext @{ var node = new DynamicNode(1157); foreach (var page in node.GetChildrenAsList.Items.Where(n => n.Visible && (n.GetPropertyValue("maal", "0").AsInt() > n.GetPropertyValue("opnaaet", "0").AsInt()))) { //do your stuff with page here } }Dave
Well, it just gives me an error like:
umbraco.MacroEngines.DynamicNode' does not contain a definition for 'GetPropertyValue'
Did you have the @using and @inherits directives in your macro cshtml script ?
Yes, I have:
Try putting the inherits as last
What version of Umbraco are you using ?
Well, no change :(
I'm using version 4.7.0
Can you post your entire code ?
Yes, of course:
Can you try this :
@using umbraco.MacroEngines @using umbraco.cms.businesslogic.member @using System.Net.Mail @inherits DynamicNodeContext @{ var members = Member.GetAll; try { foreach(var item in members.Where(x => x.getProperty("afsluttedeProjekter").Value.ToString() == "21")) { DynamicNode Node = new DynamicNode(1157); var Content = "Følgende projekter er afsluttet:\n\n"; var Projects = ""; int i; foreach (DynamicNode page in Node.GetChildrenAsList.Items.Where(n => n.Visible && (n.GetPropertyValue("maal", "0").AsInt() > n.GetPropertyValue("opnaaet", "0").AsInt()))) { Projects = Projects + "Opnået: " + @page.GetPropertyValue("opnaaet") + " - Mål: " + @page.GetPropertyValue("maal") + ""; } if(Projects != "") { @SendMyMail(@item.Email.ToString(), "Afsluttede projekter", @Content + @Projects); } } catch(Exception ex) { Response.Write(ex); } } @helper SendMyMail(string email, string subject, string projects) { try { if(email != "") { MailMessage mail = new MailMessage(); mail.From = new MailAddress("kma@moskjaer.dk"); mail.To.Add("kma@moskjaer.dk"); mail.Subject = subject; mail.IsBodyHtml = false; mail.Body = projects + "\n\n" + "Venlig hilsen"; SmtpClient smtp = new SmtpClient(); smtp.Send(mail); } } catch(Exception ex) { Response.Write(ex); } }
I have tried it, but still same error:
Testalert.cshtml(14): error CS1061: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'GetPropertyValue' and no extension method 'GetPropertyValue' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference?)
one more try :
@using umbraco.MacroEngines @using umbraco.cms.businesslogic.member @using System.Net.Mail @inherits DynamicNodeContext @{ var members = Member.GetAll; try { foreach(var item in members.Where(x => x.getProperty("afsluttedeProjekter").Value.ToString() == "21")) { DynamicNode Node = new DynamicNode(1157); var Content = "Følgende projekter er afsluttet:\n\n"; var Projects = ""; int i; foreach (DynamicNode page in Node.GetChildrenAsList.Items.Where(n => n.Visible && (n.GetPropertyValue("maal").AsInt() > n.GetPropertyValue("opnaaet").AsInt()))) { Projects = Projects + "Opnået: " + @page.GetPropertyValue("opnaaet") + " - Mål: " + @page.GetPropertyValue("maal") + ""; } if(Projects != "") { @SendMyMail(@item.Email.ToString(), "Afsluttede projekter", @Content + @Projects); } } catch(Exception ex) { Response.Write(ex); } } @helper SendMyMail(string email, string subject, string projects) { try { if(email != "") { MailMessage mail = new MailMessage(); mail.From = new MailAddress("kma@moskjaer.dk"); mail.To.Add("kma@moskjaer.dk"); mail.Subject = subject; mail.IsBodyHtml = false; mail.Body = projects + "\n\n" + "Venlig hilsen"; SmtpClient smtp = new SmtpClient(); smtp.Send(mail); } } catch(Exception ex) { Response.Write(ex); } }
Still same error, but related to the following line:
Projects = Projects + "Opnået: " + @page.GetPropertyValue("opnaaet") + " - Mål: " + @page.GetPropertyValue("maal") + "";Update: Sorry, my mistake - it seems it is still the following line which causes the error:
foreach (DynamicNode page in Node.GetChildrenAsList.Items.Where(n => n.Visible && (n.GetPropertyValue("maal").AsInt() > n.GetPropertyValue("opnaaet").AsInt()))) {Change @page to page.
No change :(
Maybe it's the AsInt() function causing the problem ? Can you remove that and use a normal cast to int ?
Do you mean like Convert.ToInt32(var)?
Yep
Does not change the outcome. If I change it like this:
foreach (DynamicNode page in Node.GetChildrenAsList.Items.Where(n => n.Visible && (Convert.ToInt32(n.GetProperty("maal").Value) > Convert.ToInt32(n.GetProperty("opnaaet").Value)))) {Projects = Projects + "Opnået: " + @page.GetProperty("opnaaet").Value + " - Mål: " + @page.GetProperty("maal").Value + ""; }
I don't get any errors, but no usefull output either.
It seems to be working now. I get emails as I should.
Thank you very much for your help, Dave
What did you change to get it working ?
Well, it is sort of embarrassing :) Earlier on, I made a Response.Write to output the value of the variable Projects, to the screen, but in the latest version it just spits out an e-mail, and no output on the screen.
It seems though, I cannot use the GetPropertyValue(var) in this version of Umbraco, but only GetProperty(var).Value.
Glad you worked it out
Not without your help :) Thanks
It's me again :)
The DynamicNode still puzzles me. If I want to select all nodes with the property slutdato equal to yesterdays date, I get this error:
System.NullReferenceException: Object reference not set to an instance of an object
When trying to do the following:
foreach (DynamicNode page in Node.GetChildrenAsList.Items.Where(n => n.Visible && (Convert.ToDateTime(n.GetProperty("slutdato").Value) == DateTime.Today.AddDays(-1)) && (Convert.ToInt32(n.GetProperty("maal").Value) > Convert.ToInt32(n.GetProperty("opnaaet").Value)))) {Some code stuff...
}
Does your date property have a value ?
Dave
Yes, it does. It is a Datepicker-property.
Well, I've got it solved - damn case-sensitive coding :)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.