I'm trying to create a Projection Query that has a Title Part filter based on a property of the current content item - let's say the Display Text ({Content.DisplayText}) for example.
The query is not working and when I debug the solution and set a break point on the GetFilterPredicate method of the StringFilterForm class the token value is always coming through as an empty string. It's as if it's not being resolved. I am seeing the same behavior for all the tokens in the Content Items group.
Other tokens are working just fine, like the QueryString ({Request.QueryString:*}) token for example.
Why are the Content Item tokens always coming through empty in my query filter? I'm using Orchard v.1.7.1.0
This is not how it works. Tokens are not meant in this context to generate query constraints on the content item properties. Tokens can only be used there to provide values for parameters of the query. If you want to filter on the title of a content item, use a title part record filter.
2 years later, but in Orchard 1.9.2 you can query based on the current content item using the token:
{Request.Content.*}
I was missing the Request part of the token. Not sure if this worked at the time I originally asked the question.
Related
I need to create an item in SP list. Unfortunately it does not work due to a Lookup field to another list.
Both lists exceed the list view threshold.
I tried more ways but got the same error.
Is there away to fix it?
attempt01
attempt02
Try using a SharePoint REST call instead. In my example below I'm updating an item, but you can create items too by simply using the PUT method.
The data to use is:
Site Address = Your full site URL.
Method = PUT to create new or PATCH to update existing.
Uri = The REST call portion of the URL, using the GUID ID of the list in question and the item ID of the specific item to be updated.
Headers = If-Match use *, Content-Type use application/json;odata-verbose, Accept use application/json;odata=verbose
Body = {"__metadata":{"type":"SP.Data.MyListListItem"},"MyField":"NewFieldValue","My2ndField":"New2ndFieldValue"}
NOTE: The double underscore before metadata.
NOTE: type is defined as "SP.Data. concatenated with the List Name, concatenated with ListItem"
NOTE: Multiple fields are updated in "name":"value","name":"value" pairs separated by commas.
I am trying to use Projection Query in orchard to filter my Projection based on the current Page. Right now I have a contentItem with a field called PageName which I am trying to match the value of. Can this be achieved using projections? I know that Tokens doesn't work in this scenario. What would be the best step of achieving what I am trying to do?
The tokens is well suited for this scenario.
Get current content item by token:
{Request.Content}
Get field by token:
{Content.Fields.YourPartName.PageName}
By combining these two tokens you can get what you need:
{Request.Content.Fields.YourPartName.PageName}
You can find token 1 and 2 in the drop-down list of tokens when you edit query filter.
I'm been searching around, and I dont understand why it is, that if I create a query for the projection and I say I want to filter a field of the returned Content Type by a Field of the current user, that no rows are returned.
If I replace the token with a hard coded value, it does work. I'm just missing some important understanding about why the token has no value.
This is not how it works. You may use tokens in projections as long as they are not expected to vary per record. Tokens can be used if they are external data (querystring parameters, etc.) To make your scenario work, you'll have to build your own filter.
EDIT: Rephrased issue
I think there is either a bug or I am doing something wrong.
I add a field to the type Blogpost. This field is of type
Contentpicker. I call it Related Page.
Then I create to regular pages (ContentType Page).
I create 4 blogposts. Two blogposts get PageOne as selected value in the RelatedPage field. The other two posts get PageTwo as selected value in the RelatedPage.
Now I create a query with filter ContentType is BlogPost. And a filter with Blog Post.Related Page equals {21} (that is the Id of PageOne).
I would expect to get results BlogPostOne and BlogPostTwo. Instead I don't get results. Actually I wanted the pageid to be retrieved from the page the widget is placed on but couldn't get it to work, so I reduced back to a predefined value instead of dynamic for the filter. But like I said no results.
So is the query wrong and how should I do it then. Or is there a bug with filters for ContentPicker fields.
P.S. I will also submit an issue in Codeplex.
UPDATE
In Tokenizer all the values that contain { } are being seen as tokens and therefore are replaced. The problem is that the Ids of content items in a contentpicker field are stored with accolades. So when having {21} as the value for the filter, 21 gets tokenized and since there is no value for this token the value becomes empty. When skipping the tokenizer it works (while debugging). But one cannot skip the tokenizer, because it is very legitimate that there is a token present.
So I believe there is a bug with either the tokenizer, or the way the ids are stored in the contentitem field for contentpicker. I think it can be solved by changing the contentpicker to store numbers separated with comma's but without the accolades.
have you tried using the alias of the page instead of content id as the identifier? e.g. "/about-us", like you do in the layer rules.
I have a Content Type "News" with custom field "NewsDate" (DateTimeField) and "Active" (BooleanField)
Now I'm need to get 3 active atimes order desc by NewsDate
Get all news, make them toList() and from there manipulate the data is not a solution.
P.S. I need to do something like:
var items = contentManager
.Query(Entities[PageType.Press])
.OrderByDescending<CommonPartRecord, DateTime?>(record => record.PublishedUtc)
.Slice(0, 3);
but instead of PublishedUTC use my custom field "NewsDate" and add Active == true, However it is not possible due to Orchard architecture of storing custom data in a separate field as XML data.
UPDATED:
In a nutshell I want to generate from code behind the following Query:
DECLARE #temp as TABLE(id int, xmldata xml)
INSERT #temp VALUES(1,'<Data><News><NewsDate>07/14/2011 11:42:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link></News></Data>')
INSERT #temp VALUES(2,'<Data><News><NewsDate>07/11/2011 12:11:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link></News></Data>')
INSERT #temp VALUES(3,'<Data><News><NewsDate>02/21/2012 16:56:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link><NewsLink></NewsLink></News></Data>')
SELECT
TOP 3 [id],
[xmldata].value('(Data/News/NewsDate)[1]', 'datetime') as NewsDate
FROM #temp
ORDER BY NewsDate DESC
P.S. I looked through the code for DynamicContentQueryTests, however all the examples uses the Part, and in my case Fields are just in the ContentItem:
E.g. News content type contains NewsDate field (datetime field) and some parts as well
Any suggestions are greatly appreciated.
Querying fields is possible since 1.4 through Projector and underlying index tables and new APIs on Content Manager. Your simplest bet actually may be to create a projection.
To get the values of fields that have been attached directly to a Content Item, you need to first look for the Content Part with the same name as the item, which is created by Orchard. So in your case in the Parts list for each News Content Item you'll find a part called "NewsPart", and inside this the Fields property will have your NewsDate and Active fields.
However, like you say Orchard serializes the field values into XML for storage to prevent it having to change the database structure every time you add/remove a field to/from a content type. For this reason, querying and ordering by fields is not recommended because all the serialized data needs to be de-serialized for each Content Item. If you want to be able to do this, the best way is to make your own Content Part with a Content Part Record and use your own table for storage, then you can do this:
contentManager.Query<NewsPart, NewsPartRecord>()...
...and query/sort on whatever values you like.
Bertrand is correct. Check this link : http://www.davidhayden.me/blog/projector-module-in-orchard-cms. You can implement your requirements easily with Projection Module. The link will tell you the steps to do that. If you don't want a widget, you can create a page with your query too. Once the module is enabled, you will see the option to create a Projection Page in the left hand side navigation.
EDIT :
Can't you simply parse the XML? You can query your content type 'News'. Something like -
var contentItems = contentManager.Query<ContentPart>("News").Join<TitlePartRecord>().Join<AutoroutePartRecord>().Join<CommonPartRecord>().List();
Once you have that, you can access the XML data by :
foreach (var item in contentItems)
{
var contentItem = (ContentItem)item.ContentItem;
ContentItemVersionRecord contentItemRecord = contentItem.VersionRecord;
string data = contentItemRecord.Data;
//Call some function here to parse 'data' and store the object in the list.
}
'data' has the information in XML format that you need.
You can parse it and then store the objects in your list that you can order by your custom field.