2

I am using following code to retrieve component by Title through core service in Tridion 2013 -

var compData = client.GetSearchResults(new SearchQueryData()
        {
            FromRepository = new LinkToRepositoryData() { IdRef="tcm:0-24-1" },//tcm id of publication
            IsTitleCaseSensitive = false,
            Title = "DemoComponent",//component title
            SearchInSubtree = false,
            ItemTypes = new ItemType[] { ItemType.Component},
            SearchIn = new LinkToIdentifiableObjectData() { Title = "DemoFolder", IdRef = "tcm:24-3251-2" }//name and tcm id of folder in which component resides
        });

This code returns null in compData instead of component, Am I missing something here ?

  • I don't see any issue with code, can you please verify the values that have provided. Seems to be, some information is not matching. – Hiren Kaku Jul 7 '15 at 4:51
  • 1
    Search relies on an index being built correctly. Does the same search return the Component within the CME? If not, perhaps your search is not working correctly (e.g. services stopped, wrong configuration, etc.) – Peter Kjaer Jul 7 '15 at 8:27
1

There is no issue with your code. But you can try this one (it is working fine for me) -

public string getcomponentid()
        {
            var client = Utility.GetCoreServiceSettings();
            string result = "Item not found";
            string TargetFolderTcmId = @"tcm:5-1945-2"; // Put your folder tcm id or Folder Webdav url here
            string title = @"Component Title";// Put your component title here

            var productsXML =
              client.GetListXml(TargetFolderTcmId,
              new OrganizationalItemItemsFilterData
              {
                  ItemTypes = new[] { ItemType.Component }
              });

            foreach (var product in productsXML.Elements())
            {
                string tcmID = product.Attribute("ID").Value;
                var productData = client.Read(product.Attribute("ID").Value, null) as ComponentData;
                // Check your title
                if (productData.Title == title)
                {
                    return tcmID;
                }
            }
            return result;
        }

Please Check the below url for more detail. https://justsayantan.wordpress.com/2015/07/07/retrieving-component-by-title-using-core-service/

1

When you search item and it is not returned which means that items are not getting indexed. There could be two issues:

  1. Search is not properly configured. Please refer: Search configuration to fix any configuration issue.
  2. With Tridion 2013, there is an issue with indexing. Please refer: Known issue with indexing

Please verify both to make sure there are no configuration issues.

For the time being, you can run following powershell commands to index the items manually:

  1. Execute Sync-TcmSearchIndex on powershell to reindex all publication
  2. Execute Sync-TcmSearchIndex with a TcmRepositoryIds parameter containing list of publication URIs if you want to re-index a set of publication or a specific publication

And to monitor the indexing status Get-TcmQueueInfo command which will give items remaining to be indexed.

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.