Using JScript within Queries
From Sense/Net 6.0 Wiki
Note: Using JScript to generate dynamic DateTime values is deprecated. It is advised to use Dynamic DateTime tags within the query instead.
JScript tags can be embeded within queries using the [jScript]...[/jScript] markers. JScript.NET language elements can be nested within these queries which are using the System namespace.
[edit] Examples
Lets assume that you are storing custom defined Article items within the /Root/Articles folders with a yyyy/mm/dd folder structure based on when they were published (E.g. if an article was published on 29th September, 2008 it would be stored within the /Root/Articles/2008/09/29 folder). A query that returns the elements from the folder of today or yesterday looks the following way:
Search expression within XML
<?xml version="1.0" encoding="utf-16"?> <SearchExpression xmlns="http://schemas.sensenet.hu/SenseNet/ContentRepository/SearchExpression"> <And> <Type nodeType="Article" /> <Or> <String op="StartsWith" property="Path">/Root/Articles/[jScript]DateTime.Now.AddDays(-1).ToString("yyyy'/'/MM'/'dd")[/jScript]</String> <String op="StartsWith" property="Path">/Root/Articles/[jScript]DateTime.Now.ToString("yyyy'/'/MM'/'dd")[/jScript]</String> </Or> </And> </SearchExpression>
Search expression within code
NodeQuery query = new NodeQuery(); query.Add(new TypeExpression(ActiveSchema.NodeTypes["Article"])); ExpressionList orExp = new ExpressionList(ChainOperator.Or); orExp.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "/Root/Articles/[jScript]DateTime.Now.AddDays(-1).ToString(\"yyyy'/'/MM'/'dd\")[/jScript]")); orExp.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "/Root/Articles/[jScript]DateTime.Now.ToString(\"yyyy'/'/MM'/'dd\")[/jScript]")); query.Add(orExp);
