1

I am using sitecore 9.0.1 with sxa 1.7 I have created a template field called "Name" with type as drop list and specified the datasource to point to the data which is in Data Folder "/sitecore/content/Research/ResearchSite/Data/Titles".DropList is showing the item names which is created under that title folder . How to fetch the value inside the items. For example i need to fetch "Energy" from the Titel1 item.

enter image description here

enter image description here

Thanks

2
  • I think you need to create a custom field in your case Feb 23 at 8:52
  • yes have already extended a existing component and added the custom field @Amro Mustafa
    – Vinaya
    Feb 23 at 9:21
2

Instead of Droplist, you can take Droplink because Droplist holds item name but Droplink holds the ID of that item, later on from that id you can get Item and access its field.

LookupField address= (LookupField)mainPage.Fields["Address"];
Item addressItem = address.TargetItem;
string displayName = addressItem.Fields["DisplayName"].Value;

You can check by changing the raw value -

enter image description here

For further read - A Droplist stores the name of the items. It allows the editors to select one value from the dropdown list. Droplist is similar to Droplink, the only difference is – Droplist stores item name while the Droplink stores the ID of the item.

3
  • Yes now i am able to retrieve Item Id but how can i fetch the value @Gaurav Agarwal
    – Vinaya
    Feb 23 at 7:16
  • See code above I added, you need to cast this to LookupField and get item from it, then you can fetch the value from that item. Feb 23 at 7:32
  • I have not created VS solution for it can't we achieve this in sitecore itself?@Gaurav Agarwal
    – Vinaya
    Feb 23 at 7:42
0

One solution would be to use a rendering variant reference item, which lets you display fields from a referenced item. For this you would need to change your field from a droplist to a droplink, multilist or treelist for example as they store the referenced item's ID.

You can take a look at the sitecore doc https://doc.sitecore.com/developers/sxa/18/sitecore-experience-accelerator/en/walkthrough--using-the-rendering-variant-reference-item-to-display-fields-from-a-linked-item.html which describes step by step how to create the rendering variant reference item and render the fields.

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.