1

I am adding the Item created field to Solr index. This is the code

        public override object ComposeValue(object source, ConcurrentDictionary<string, object> context)
        {
            if (context == null || source == null || !(source is CatalogItemBase entity))
            {
                return null;
            }
            return entity.DateCreated;
        }

I have tried DateCreated but this is not giving the correct value. I want to use the _Created Sitecore field which records the item created date. Is there any way I can read the item and get the item created date which is _Created field?

0

The CatalogItemBase class has a field SitecoreID

public class CatalogItemBase : CommerceEntity
  {
    /// <summary>Gets or sets the sitecore identifier.</summary>
    /// <value>The sitecore identifier.</value>
    public string SitecoreId { get; set; }
   }

You can get the Sitecore item based on SitecoreID and the you can get the field value like on below code.

 var item=Sitecore.Factory.GetDatabase("web").GetItem(new ID(entity.SitecoreId));
 var dateCreated=item["__Created"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.