I am Sitecorian. I love working on Sitecore. But I
usually don't like to access Sitecore items through its field. So I use TDS
package to generate entity for each templates.
TDS is great and making my life much easier to write
code and allow me to focus on accessing data from Sitecore.
Recently I have added "Mulitilist with
search" field in one of my template and I was trying to create
corresponding field in code through TDS.
I generated code but to my surprise I was unable to
access it in Sitecore. When I check TDS generated code, I got "Could not find Field Type for Multilist
with Search". I tried with some different way to solve this. But
didn't succeed. I googled as well but didn't find anything on this.
So I believe this tip is unique in its own as Google
don't have answer on this.
I thought that let me check what the corresponding
Sitecore class is for Multilist with Search fields.
I didn't found any class. There is only Multilist class
is available.
I concluded that if Sitecore have only Multilist class
then lets write this field entry in TDS code generated file with Multilist.
So I added below line
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - Velir.tt", "1.0")]
public CustomMultiListField Non_Applicable_Areas { get { return new CustomMultiListField(InnerItem, InnerItem.Fields[new global::Sitecore.Data.ID("1f21d38a-c061-4d9d-92a6-f9cfba7c3c22")]); } }
Voila. It’s working fine and giving me values in
runtime.
Later on I again added some more fields in Sitecore and
trying to generate the TDS code. To my surprise my above code was removed by
TDS. Then I check the template generated TDS class. I observe that it’s a
partial class. So I define that entry in some another file as below
namespace MyProject.Library.TDSTemplates
{
/// <summary>
/// Duration
/// <para></para>
/// <para>Path: /sitecore/templates/My Project/Component Templates/Animal</para>
/// <para>ID: aa5b4a8e-d112-45f1-83f9-fef307938b77</para>
/// </summary>
/// <remarks>
/// This example shows how to specify the <see cref="Animal{T}"/> type as a cref attribute.
/// </remarks>
public partial class Animal : global::Sitecore.Data.Items.CustomItem
{
/// <summary>
/// The Non Applicable Areas field.
/// <para></para>
/// <para>Field Type: Multilist</para>
/// <para>Field ID: 1f21d38a-c061-4d9d-92a6-f9cfba7c3c22</para>
/// <para>Custom Data: </para>
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for
Sitecore - Velir.tt", "1.0")]
public CustomMultiListField Non_Applicable_Areas { get { return new CustomMultiListField(InnerItem, InnerItem.Fields[new global::Sitecore.Data.ID("1f21d38a-c061-4d9d-92a6-f9cfba7c3c22")]); } }
}
}
OMG J .My
code is again working fine and now it’s not removing by TDS code as well.
No comments:
Post a Comment