SOLVED

Email scripting with custom object - show whole list, but only particular fields

Go to solution
Phillip_Wild
Level 10

Hi team

I'm trying to output a custom object, but only a particular field. So let's say I have a custom object named CustomObject with the fields Name and Description. I can use:

${CustomObject}

To output all fields. Great. I can also use:

${CustomObject.get(0).Name}

To output the first record of that custom object, and the Name field.

But....I can't for the life of me work out how to output the Name field for every record in that custom object. I've tried things like:

${CustomObject.Name}

${CustomObject.get.Name}

${CustomObject.get().Name}

With no luck. What am I missing here? I'm sure this can't be that hard....

Thanks!

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

P.S. The alternative method Nicho is driving at is this:

#set( $allNames = [] )

#foreach( $object in $CustomObjectList )

#set( $tmp = $allNames.add($object.Name) )

#end

Naturally, I like my method more as it's shorter + lets you take advantage of Velocity's underlying Collections support.

Also, for those unfamiliar, Unicode/ASCII character x001e (31) is the Record Separator (RS) character. This is the only character guaranteed per formal standard to not be found within a value, but to only be a separator between values.

That is, we often treat commas and semicolons as separators, but that only works if you know ahead of time that your values will never contain commas and semis, or if you have an additional layer to act as an escape mechanism (double quotes)... which then in turn needs to be escaped... covering all the bases can take a lot of code.

In contrast, if you just use RS between values you're always safe, no need for other escaping. To put it more simply, join(RS).split(RS) always works even if you don't know the data.

View solution in original post

12 REPLIES 12