Item to be bucketed according to a date field when created - sitecore

I have created a content item at /sitecore/Home/FootballFever/Articles and have given insert option so that we can add only items of templates "Article".As of now,these article items are bucketable according to a field created date.
Now, i have insert option "Add Article" and "Insert from Template" buttons in the Home ribbon "Insert" block. When i create an item through "Insert from Template", the item automatically gets added in respective bucket with path as created date. for example if the item has created date is "7/21/2014" then path will be "/Articles/2014/7/21/ ".
But when i click on "Add Article", the item gets added in /Articles and i have to Sync everytime to get it to correct path.
How can I have the same behavior as that of "Insert from Template" but with path having Release date which is a field of template "Article"?

Please make sure that Article template has Bucketable field checked in its Standard values (for Article template).
If not, when you add a new item into buckets folder, newly added item itself is not bucketable, unlike the rest already existing items from the same bucket folder.
I have just made a proof of concept on my sandbox environment and can confirm that in case you add a new item with Bucketable checked by Standard values - it comes into a bucket straight away and you do not need to perform Sync.
Hope this helps.
UPDATE: I have written a blog post specially to cover your question,with comprehensive description.
http://blog.martinmiles.net/post/understanding-buckets-adding-new-items-to-buckets-correctly

By default, items will be structured in bucket folders, five levels deep based on the date and time the item was created. There are a couple of other built in rules you can use like using part of the Guid or part of the name. The thing to note here is that these are all things that are available on item creation. If you want to structure your articles based on a custom 'Release Date' then you will need to write a custom rule and you will also have to implement an OnItemSaved event handler. Here is a article on how to write the custom rule.
Generally you don't have to worry about how the items are structured in your bucket. Editors should be using the search tab to find the items they need.
Having said that, this SO post discusses how to structure your bucket items based on a custom field. Some things to note here is that this is generally a global change. There are ways around it that enables you to have different strategies for different buckets but you'll then have to do additional work to override the LinkProvider and potentially other things.

Related

Best practice for accessing Sitecore Items via code

Quite new to Sitecore and would like to understand the best way to access sitecore items. I've seen couple of ways:
Create Page ID field and get all items for given template and folder. Then do linq query on page ID.
Store all Page ID (Sitecore Item ID) on Constants file. Use this to query Sitecore using GetItem(itemID) API.
Could someone please suggest what's the best practice. Either way, I can see that there will be huge Constants file containing either custom Page ID or Sitecore Item ID.
My worry is do we really need to manage this Constants file or is there an elegant way to query CMS contents for given Page.
Thanks.
Approach 1 seems a bit odd. I don't really see why you would get a collection of items first when you already have the ID, but maybe I've misunderstood what you're saying.
I think a combination of 2 things you mention is best.
Constants classes are good for "landmark" items that will always definitely be there, so its fine for the GUID to be in code.
Some of these landmark items can be "configuraton items" that have fields containing the IDs of other items (These fields might have names like "Templates allowed in search"). This approach allows some flexibility for change by Sitecore users as the site evolves.
If you're concerned about the management of a constants file, I have to wonder how many items you need to access by ID. Sitecore items have properties like Parent and Children. You can also find items by template type etc.
This approach works well for me. I certainly don't think there is a more elegant way of getting strongly typed references to Sitecore items.
Personally, I prefer not to use constants files. What happens if your client or one of your developers deletes one of those items and creates a new one? One of the fundamental principles of Sitecore is that items can be added and removed by users who are not necessarily "technical" personnel.
Sitecore provides "Insert Options" so that you can specify what types of items can be added to each folder, and also grants the ability to protect certain items from deletion, via Roles and User Permissions. What does this mean conceptually? It means that Sitecore is set up such that the system architects/developers can create a structure that is not to be violated, while the content editors can add or remove content within that structure. In other words, Sitecore is designed to provide a framework in which the items can change but the location of each type of item is pre-determined.
As such, I suggest that you use the Custom Item Generator module available in the Sitecore Marketplace (free). CIG generates C# class representations (models) of your templates, and makes all fields into properties (I don't want to get too off-topic, but this is an awesome feature of CIG, especially when working with newer developers). You can add your own methods to your CIG classes for getting children of a particular type. For example, on a site in which the Profile Page is a direct child of the Homepage the following method could be added to the CIG HomepageItem.instance.cs file's HomepageItem partial class:
...
public partial class HomepageItem
{
public ProfilePageItem GetProfilePage()
{
//note that .IsOfType(...) is pseudo-code and not a real method, but I do
// suggest that you define an extension for it
return InnerItem.Children.FirstOrDefault(i => i.IsOfType(ProfilePageItem.TemplateId));
}
}
Be sure that you are assigning Insert Options to restrict the types of items that can be added as children to each item you make (add them on the Standard Values and not on the individual content items). I also suggest that you make a separate Template that inherits from Common/Folder for every folder that you use in the content tree. This way you can use CIG for your entire structure, via:
...in your Globals Item's CIG class...
public partial class GlobalsItem
{
public SlidesFolderItem GetSlidesFolder()
{
return InnerItem.Children.FirstOrDefault(i => i.IsOfType(SlidesFolderItem.TemplateId));
}
}
...in your Slides Folder Item's CIG class...
public partial class SlidesFolderItem
{
public IEnumerable<SlideItem> GetSlides()
{
return InnerItem.Children.Where(i => i.IsOfType(SlideItem.TemplateId));
}
}
and then you can get your Slide items via:
...
var slidesFolder = globals.GetSlidesFolder();
var slides = slidesFolder != null ? slidesFolder.GetSlides() : null;
Remember that CIG, Insert Options, and templates for each type of folder will enable you to create an iron-clad structure for your site that will not break if content editors make unexpected changes like replacing items.
Let me know if you have any questions on this. Good luck, and Happy Coding! :)

Search tags/facets in Sitecore Item Buckets

I'm looking to use the Sitecore Item Buckets package from Shared Source since I needed faceted search functionality and it makes sense to use the built in functionality rather than writing by own Lucene.Net search.
Sitecore Item Buckets
I'm having trouble with the search, or maybe I am reading the documentation wrong.
According to the documentation in section 2.2.3 & 3.1.3 I just need to mark a field as "Is Facet" and my filter will show in the search results.
I've also defined a tag field on the template and changed the Tag Parent field in "/sitecore/system/Modules/Item Buckets/Item Buckets Settings" to point to correct folder. This is working correctly, I can apply a set of tags to an item and search from the Bucket UI using "tag:CSharp" and it brings back the correct results, but again there is no filter shown in the list. I've rebuilt the bucket indexes in all cases.
Am I missing something? Should these show up in the list automatically, do I need to change some settings or provide my own implementation?
Screenshot
This is all within the Buckets Client UI, I haven't started writing any code yet, and on a clean install of Sitecore 6.5 (update-5/rev. 120706).
I'm not sure the documentation wording around this is entirely clear at the points I've mentioned. If you read further down the document though, section 4.3:
Item Buckets ships with 5 different types of faceting.
Templates
Fields
Dates
Locations
Authors
If you would like to introduce your own faceting categories then you only need to implement the IFacet interface.
There is an example of IFacet implementation in the documentation, or use dotPeek to look at the implementations of the existing Facets.
You also need to add an item to Sitecore: /sitecore/system/Modules/Item Buckets/Facets

Selecting a datasource item for preset components

Before digging into my explanation i will summarize my question:
How do I provide the user (editor) with a user-friendly possibility to select a datasource item for sublayouts that are preset on the standard values?
My situation is as follows:
I have a page template, with pre-defined layout on the standard values.
Let's say the layout consists of:
one placeholder "wrapper"
one sublayout "content"
This sublayout is pre-defined on my page template, but can also be placed in the placeholder using the Page Editor.
It needs to have a datasource item that defines a Title and Body value.
Now, if a user adds this sublayout to the placeholder using the Page Editor, he will get a nice interface to select or create the datasource item (see screenshot).
However, if the sublayout was pre-defined on the standard values, it will be added without datasource (I can't pre-set the data source in the standard values because it's still unknown by then).
At that point there seems to be no way to get to that nice interface for selecting or creating a datasource item.
Ideally I want to be able to add a field to my template that can hold a datasource item which the user can select/create using the nice interface. I looked at the datasource field type, which could be an alternative, but it's still not exactly what I want.
Bare in mind that the content sublayout is just an example.
I understand that in that specific case I could solve it by always adding a title/body field to the template which hold the values if there is no datasource, but for my real world problem that won't suffice.
I don't have a whole lot of experience with the Page Editor (with the new way of working with it) so I would like to get some advice on this subject.
According to what you said here:
Ideally I want to be able to add a field to my template that can hold a datasource item which the user can select/create using the nice interface. I looked at the datasource field type, which could be an alternative, but it's still not exactly what I want.
It seems you want an intuitive data source selector interface in the CMS shell similar to the Page Editor-based UI.
Quick answer: Simply put, there's nothing that does this for you in Sitecore.
Longer answer: There are still some options for you, e.g.
Define a global "dummy" data source and set that to be the data source set in in Presentation > Layout Details of the template's standard values. So every time you create a new page, it will always point to that dummy value to show something.
From here you can do a few things:
If the user must use the shell UI and not Page Editor, they can simply create another data source item for the specific page and update that page to point to it using the existing native interface in Layout Details.
Another option is to write an event handler, say for item:created or similar that when you create an item, auto-create a corresponding data source item for this specific page (whether this auto-created item be a sub-items or global item...) then programmatically set this to be the data source. A similar concept is shown in this video by Nick Wesselman: http://www.techphoria414.com/Blog/2012/May/Sitecore_Page_Editor_Unleashed

Add Activities to Activity Dropdown in Task Work Item

Is there a way to modify the values that are currently in the Activity dropdown for a Task work item? Here's the current list:
Deployment
Design
Development
Documentation
Testing
Requirements
Sure, you have to edit the Process Template or the Work Item type of the existing Team Project you want to change.
This article gives you information about how to edit a Process Template.
If you want to edit the Work Item of an existing team project is almost the same process, only the start is different as you have to select this command:
Once your Task Work Item Type is selected, double-click on the Activity field in the Fields tab.
Then in the windows that opens, go to the "Rules" tab and double-clik on the "SUGGESTEDVALUE" line.
Then change the lines you want.
Finally save the Work Item type, if you're from the process template then follow the procedure told in the article, if you're from the Work Item in an existing Team Project, you just have to save for the change to be effective.
BUT, beware (for the existing Team Project case) that if some Work Items already exist in your Team Project that use a value you removed, these ones will generate an error the next time you'll edit them. You'll have to change the value of the Activity field to an existing one if you want the Work Item to be save-able.

Why aren't my Content Items accepting their new Workflow?

All of my Content Items in one node have a bad reference to a workflow. I am trying to create one to replace the missing Workflow. I did these steps:
Created a new workflow
Located the common inherited template that all content items in this node use.
In the standard values I chose my new workflow for the "Workflow" and "Default Workflow" fields (I think I just need default, but I am not sure.)
Saved and Smart Published.
The content items still show the GUID for the missing Workflow. I click the template name at the top of the content item, double check the standard values on the template and everything looks great.
How do I force Content Items to retrieve the correct workflow from their Templates?
It looks like your content items have broken from their standard values which is why your new standard value WF is not getting set. What version of Sitecore are you using? You can use the reset button on each content item to bring it back to the standard value just for the workflow.
Go to the View ribbon and enable Standard Fields
For each content item that has the wrong workflow, go to the Versions ribbon and click the Reset button on the left
In the pop-up scroll all the way down to the bottom Workflow section and check the boxes to reset specific fields
Repeat this process for all of the content items
Another idea is to write code to programatically reset fields or set them to a new WF