Retrieving component by Title using Core Service
Updated: Aug 15, 2019
Very often I have received the requirement for retrieving component using the core service. I have used this below code snippet many times to retrieve the component id or particular component filed. You can search the component id by providing the value of any mandatory fields. In this example I have used the “Title” to retrieve the component id.
To set a boundary of the search, I have provided the location information of the component.
Here is my Code:
Instead of hard coding your value you can pass it as a parameter.
Always try to pass webdav url of the folder instead of tcm uri.
The code is pretty straight forward as I am comparing the Title of the component. Now If you want to use a field value of the component then you can check below code –
For Example: My Component has 2 fields heading and paragraph.Now I am comparing the heading of my component
So the concept is –
Set your variable, Get the list of components as XML, Loop through each item and find out if it is the product and return.
Hope you enjoy the blog.