HI, I am writing an custom macros, which is returning a object that contain a List of objects as below.
public class EventDetail : AbstractDataContainer<EventDetail> { [RegisterColumn] public string EventType { get; set; } [RegisterColumn] public List<RegistrationContact> RegistrationContacts { get; set; } }
Now I am trying to iterate the list in the transformation as below. But it is not showing the result..
{% If(eventDetail["RegistrationContacts"].ToList()!=null && eventDetail["RegistrationContacts"].ToList().Count){ foreach (var evt in eventDetail["RegistrationContacts"].ToList()) { %} <p>{% evt.RegistrationContactName; %}<br> <a href="mailto:{% evt.RegistrationContactEmail; %}">{% evt.RegistrationContactEmail; %}</a><br> <a href="tel:{% evt.RegistrationContactPhone; %}">{% evt.RegistrationContactPhone; %}</a></p> {% } } #%}
Could you please let me know where am I doing wrong. Please help me out.
Thanks, Joyanta
Check the event log, it should tell you why your macro is failing. My guess .ToList() is crushing. There is not ToList() unless (see macro methods) you have it as custom macro. Although there is List that converts a list of objects to an ArrayList.
Hi Peter, I tried but not working.
Thanks
Hi, Could anyone please let me know how to iterate a List of object returned by macro in transformation. Its an urgent need in my project. Thanks.
your macro should work just remove .ToList():
{% res = ""; if (eventDetail["RegistrationContacts"]!=null) { foreach (evt in eventDetail["RegistrationContacts"]) { res += "<p>" + evt.RegistrationContactName + "<br>" } } return res; @%}
Did that. But Didn't work. I resolve this by removing the following statement
eventDetail["RegistrationContacts"].Count
but don't know why Count is not working. If you can tell me any other way to find out the count that will be great.
Count
Thanks.
Count doesn't work because it is not implemented. ToList() and Count() do not work (AbstractDataContainer does not have them) , but you actually you dont need them to iterate. try the script above see if it works
Please, sign in to be able to submit a new answer.