Content Query Web Part and Dates

%3CLINGO-SUB%20id%3D%22lingo-sub-6244%22%20slang%3D%22en-US%22%3EContent%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6244%22%20slang%3D%22en-US%22%3E%3CP%3EWhilst%20more%20of%20an%20advanced%20user%20rather%20than%20a%20developer%20myself%2C%20I%20think%20only%20a%20developer%20can%20answer%20my%20question.%26nbsp%3B%20I%20am%20trying%20to%20display%20a%20list%20of%20entries%20from%20my%20custom%20list%20where%20the%20%5BOrder%20Date%5D%20is%20this%20week%20(i.e.%20after%20Monday%20in%20the%20current%20week).%26nbsp%3B%20I%20don't%20believe%20this%20can%20be%20done%20via%20the%20query%20in%20CQWP%2C%20however%20I%20was%20hoping%20I%20could%20get%20users%20to%20input%20the%20week%20start%20date%20into%20a%20control%20on%20the%20page%20and%20use%20that%20field%20to%20set%20the%20value%20in%20the%20CQWP.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOtherwise%20the%20CQWP%20gives%20exactly%20what%20is%20needed%2C%20just%20need%20a%20way%20to%20set%20the%20date%20in%20the%20query%20to%20Monday.%26nbsp%3B%20Any%20advice%3F%26nbsp%3B%20Ideally%20no%20code%20solutions.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6468%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6468%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20performance%20really%20depends%20on%20the%20size%20of%20the%20list%20and%20the%20scope%20of%20the%20query.%20Also%20with%20search%20you%20have%20to%20take%20into%20account%20the%20index%20latency%20which%2C%26nbsp%3Bdepending%20on%20your%20search%20configuration%2C%26nbsp%3Bmight%20be%20causing%20not%20all%20items%20being%20returned.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6467%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6467%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EOne%20way%20to%20go%20around%20it%20would%20be%20to%20define%20a%20query%20that%20would%20get%20items%20from%20previous%207%20days%20to%20next%207%20days%3A%20that%20way%20you%20would%20be%20safe%20on%20Sunday%20(getting%20items%20from%20the%20past%20week)%20as%20well%20as%20on%20Monday%20(getting%20items%20%3C%2FSPAN%3E%3CSPAN%3Efrom%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bthe%20upcoming%20week).%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EYou%20could%20then%20sort%20items%20ascending%20by%20the%20date%20and%20do%20filtering%20in%20XSLT.%20The%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fdd583143(v%3Doffice.11).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eddwrt%20namespace%3C%2FA%3E%26nbsp%3Bcontains%20some%20date%20manipulation%20functions%20that%20could%20help%20you%20with%20that.%20It's%20not%20trivial%20but%20it's%20definitely%20doable.%20It's%20worth%20noting%20that%20this%20approach%20would%20work%20if%20the%20list%20of%20items%20is%20not%20huge%20and%20retrieving%20items%20from%20-7%20days%20to%20%2B%207%20days%20wouldn't%20return%20hundreds%20of%20items.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHope%20this%20helps%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EWaldek%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6405%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6405%22%20slang%3D%22en-US%22%3ESo%20if%20you%20create%20a%20start%20of%20the%20week%20calculated%20column%20you%20can%20filter%20by%3CBR%20%2F%3EDate%20%26gt%3B%20start%20of%20week%20and%20date%20%26lt%3B%3D%20today%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6382%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6382%22%20slang%3D%22en-US%22%3E%3CP%3EWould%20definitly%20go%20for%20search%20and%20displaytemplates%20it%20is%20much%20faster%20than%20CQWP%20you%20need%20to%20invest%20some%20time%20in%20it%20but%20it%20makes%20your%20users%20happy.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ekr%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPaul%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6376%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6376%22%20slang%3D%22en-US%22%3EThanks%20for%20the%20tips.%20The%207%20day%20filtering%20around%20today%20won't%20work%20in%20this%20scenario%20as%20the%20view%20needs%20to%20only%20show%20current%20week%20not%20last%207%20days.%20Current%20week%20being%20Monday%20to%20Sunday.%20So%20on%20a%20Monday%2C%20I%20need%20to%20see%20only%20today%2C%20on%20Tuesday%20today%20and%20yesterday%2C%20etc.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6255%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6255%22%20slang%3D%22en-US%22%3E%3CP%3EAlso%20to%20get%20the%20this%20week%20done%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.nothingbutsharepoint.com%2F2010%2F03%2F24%2Ffilter-by-events-this-week-in-a-sharepoint-calendar-aspx%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.nothingbutsharepoint.com%2F2010%2F03%2F24%2Ffilter-by-events-this-week-in-a-sharepoint-calendar-aspx%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6254%22%20slang%3D%22en-US%22%3ERe%3A%20Content%20Query%20Web%20Part%20and%20Dates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6254%22%20slang%3D%22en-US%22%3EYou%20can%20use%20the%20content%20Query%20web%20part%20for%20this%20however%20you%20might%20want%20to%20try%20using%20the%20Search%20results%20or%20Content%20Search%20web%20part.%20Then%20you%20can%20use%20Display%20templates%20instead%20of%20xsl.%20And%20specify%20queries%20through%20the%20interface.%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Whilst more of an advanced user rather than a developer myself, I think only a developer can answer my question.  I am trying to display a list of entries from my custom list where the [Order Date] is this week (i.e. after Monday in the current week).  I don't believe this can be done via the query in CQWP, however I was hoping I could get users to input the week start date into a control on the page and use that field to set the value in the CQWP.

 

Otherwise the CQWP gives exactly what is needed, just need a way to set the date in the query to Monday.  Any advice?  Ideally no code solutions.

7 Replies
Highlighted
You can use the content Query web part for this however you might want to try using the Search results or Content Search web part. Then you can use Display templates instead of xsl. And specify queries through the interface.
Highlighted
Highlighted
Thanks for the tips. The 7 day filtering around today won't work in this scenario as the view needs to only show current week not last 7 days. Current week being Monday to Sunday. So on a Monday, I need to see only today, on Tuesday today and yesterday, etc.
Highlighted

Would definitly go for search and displaytemplates it is much faster than CQWP you need to invest some time in it but it makes your users happy.

 

kr,

 

Paul

Highlighted
So if you create a start of the week calculated column you can filter by
Date > start of week and date <= today
Highlighted

One way to go around it would be to define a query that would get items from previous 7 days to next 7 days: that way you would be safe on Sunday (getting items from the past week) as well as on Monday (getting items from the upcoming week). You could then sort items ascending by the date and do filtering in XSLT. The ddwrt namespace contains some date manipulation functions that could help you with that. It's not trivial but it's definitely doable. It's worth noting that this approach would work if the list of items is not huge and retrieving items from -7 days to + 7 days wouldn't return hundreds of items.

 

Hope this helps,

 

Waldek

Highlighted

The performance really depends on the size of the list and the scope of the query. Also with search you have to take into account the index latency which, depending on your search configuration, might be causing not all items being returned.