Created
April 7, 2019 05:41
-
-
Save himanshuahuja96/7f8ef2741b453b7a78a36a2c3945ca9c to your computer and use it in GitHub Desktop.
Sitecore computed field logix to index all the fields of current item in one go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Algorithm: | |
| 1) Get all the fields of current item | |
| 2) Store all fields in an array | |
| 3) create a empty string to store all the item data and call as itemdata (typeof string) | |
| 4) Iterate through each item and push data into itemdata | |
| 5) Remove all the html using regrex from itemdata if any | |
| 6) return itemdata | |
| Basic code | |
| function getallfields(Item currentItem){ | |
| List<ID> fieldIds = null; | |
| currentItem.Fields.ReadAll(); | |
| foreach (Field field in Item.Fields) | |
| { | |
| fieldIds.Add(field.ID); | |
| } | |
| return fieldIds; | |
| } | |
| function getallData(List<ID> fields ,Item item){ | |
| string itemdata = string.Empty; | |
| foreach(field in fields){ | |
| itemdata += item[field].Value; | |
| } | |
| return itemdata; | |
| } | |
| //Use above function in the computed field and get all the data without need to create multiple computed field logics. | |
| You can extend this also like if you want to index multilist then you can add case to check if fild.type==multilist then | |
| call getalldata recursively. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment