Forum list » General discussion »
Relation-field: retrieve a specific range of articles
Pages:  1
(62 posts)

Relation-field: retrieve a specific range of articles

Do you have a good example of how to retrieve a specific range of articles from a relation field (in edit) ?

In my case, I want the user to be able to select only 10 specific nodes of a specific node type, not all of them.

(144 posts)

Re:Relation-field: retrieve a specific range of articles

Could you explain a little more on what you need? Do you have a more concrete example of what you want to retrieve? 

A couple of general examples on using a relation to fetch content:

//get current node
ArticleBase art = WAFContext.Request.GetContent<ArticleBase>();
//fetch the first 10 articles ordered by listorder (default sort order, what you see in edit)
art.Children.Query<ArticleBase>().Execute(10);
//fetch the 10 latest articles created in the last 10 days. If less than 10 articles, have been created, it will not return older articles.
art.Children.Query<ArticleBase>().Where(AqlArticleBase.CreateDate > DateTime.Now.Date.AddDays(-10)).OrderBy(AqlArticleBase.CreateDate,true).Execute(10);
(62 posts)

Re:Relation-field: retrieve a specific range of articles

Ok :)

I want to know how to overload the selection in a relation-field in edit. See screenshot example.

Attachments
(144 posts)

Re:Relation-field: retrieve a specific range of articles

To override the selection in a relation select dialogue, you need to override the RestrictSelectionOfNewRelatives. The AqlExpressionBuilder parameter is added to the query that fetches the content that is shown in the select dialogue. In the example below, the added expression means that only nodes with a specific template is shown.

public override void RestrictSelectionOfNewRelatives(AqlExpressionBuilder expressionBuilder, MemDefProperty propDef) {
        if (propDef.Id == NewsItem.PropertyIdChildren) {
            expressionBuilder.And(AqlHierarchicalContent.TemplateId == 999);
        }
        base.RestrictSelectionOfNewRelatives(expressionBuilder, propDef);
    }

You can also replace the whole dialogue with your own custom dialogue, as described in this tutorial:

http://developer.webnodes.com/replacing-the-select-related-content-dialogue

(62 posts)

Re:Relation-field: retrieve a specific range of articles

Thank you, this works fine!