Developer forum

Forum » Templates » Loop through data/values from String[] type field from index - what is the right way?

Loop through data/values from String[] type field from index - what is the right way?

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

I have an index, where one of the fields (multiple checklist) is stored as a string Array - string[]

When outputting it in a Query Publisher, i see that the field type is string[], but i am not able to get any values from it. I have tried looping it with foreach, and for - but i can not get any values or I get an error

 

foreach(var item in i.GetValue(array)) {

// gives an error

}

 

for(var i = 0; i < array.Length; i++) {

gives something in the direction of "object has no attribute length"

}

 

What is the correct way to get data from a string[] field from an index?

 

/Hans

 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

What if you cast it to an string[]?

var items = (string[])array;

for(var i = 0; i < items.Length; i++) {

}

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Works perfectly

Thank you Imar 👍

/Hans

 

You must be logged in to post in the forum