2

I need to fetch multiple custom metas using Content Service microservice in Web 8.5, found that this is the issue in odata in earlier versions as described in the below URL http://www.tridiondeveloper.com/odata-how-to-query-multiple-custom-metas

Can this be achieved using the Content Service, or is it still the issue?

2
  • I think it's possible, are you looking for CIL APIs for custom meta query? Here is the list of Content Service API documentation docs.sdl.com/LiveContent/content/en-US/SDL%20Web-v5/…
    – Velmurugan
    Commented Jan 4, 2019 at 10:26
  • @Velmurugan, using /CustomMetas, we will be able to search for only 1 field, not multiple fields, do you have any example?
    – GVK
    Commented Jan 4, 2019 at 12:45

1 Answer 1

4

Example:

using log4net;
using System;
using System.Collections.Generic;
using Tridion.ContentDelivery.DynamicContent.Query;

namespace SDL.CIL.Test
{
    internal static class Program
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(Program));

        private static void Main(string[] args)
        {
            Query query = new Query();

            List criteria = new List
            {
                new ItemSchemaCriteria(340),
                new PublicationCriteria(8),
                new ItemTemplateCriteria(350)
            };

            query.Criteria = CriteriaFactory.And(criteria.ToArray());

            List artickecategoryQuery = new List();
            CustomMetaValueCriteria nameCriteria = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("field-name1"), "value", Criteria.Equal);
            artickecategoryQuery.Add(nameCriteria);
            query.Criteria.AddCriteria(CriteriaFactory.Or(artickecategoryQuery.ToArray()));

            CustomMetaValueCriteria authorCriteria = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("field-name2"), "value", Criteria.Equal);
            artickecategoryQuery.Add(authorCriteria);
            query.Criteria.AddCriteria(CriteriaFactory.Or(artickecategoryQuery.ToArray()));

            string[] componentsUris = query.ExecuteQuery();

            foreach(var itemId in componentsUris)
            {
                Console.WriteLine(itemId);
            }

            Console.WriteLine("Finished");
            Log.Info("Finished");
            Console.Read();
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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