1

First question on here and new user of Ampscript - please be gentle!

Primarily for debug purposes I would like to use the LookupRows function to return a subset of rows from a number of Data Extensions, but rather than then returning a specific field I would like to return all the fields from all the rows including the header row.

As I will be repeating this process on Data Extensions of all shapes and sizes, I was looking for a way to do with programatically, and thus dynamically deal with Data Extensions with different field and row counts.

I did look through the documentation but couldn't find an example, or even a function that would return a field header.

1

Have you tried server side javascript for this? You can either get all the fields returned as a JSON object:

http://help.exacttarget.com/zh-HK/documentation/exacttarget/content/server_side_javascript/server_side_javascript_syntax_guide/core_library_server_side_javascript_functions/data_extension_server_side_javascript_functions/#section_11

or even get all the rows with all fields as a JSON object: http://help.exacttarget.com/zh-HK/documentation/exacttarget/content/server_side_javascript/server_side_javascript_syntax_guide/core_library_server_side_javascript_functions/data_extension_server_side_javascript_functions/#section_25

Note that the retrieve is limited to 2500 rows.

You can then access any of this data in ampscript by passing values between them. There are further articles on how to achieve this.

0

Welcome to the world of AMPscript! You'll soon discover that it's like a whole new world, frequently likened to a magic carpet ride.

Retrieve all rows: As far as I know, you can't just call all the values in the DE w/o some value to match on. One work-around for this is to create a column with a default value of 'A', so that every row has this value and it can be used in the LookupRows' where clause.

The get the columns - I don't know of this. However, you're going to have to type the column name in to call the value, so typing it twice may be your only option. If you're looking to create some snippet that just calls everything in DE name = "ThisDataExtension", this won't be possible^.

^ If I'm wrong, I'd invite a contradiction. This is an obstacle I've yet to solution.

  • Thanks @edu8ardo, I am only returning a subset of rows (not all), but I do want all the fields/columns. It was writing out all the column names manually that I was trying to avoid if possible. – Paul Moody Sep 22 '14 at 16:12
0

I haven't figured out a way to do it with ampscript either. Usually when I need to do something like this I'll switch over the Server-side Javascript. You can use the Fields.Retrieve function to grab the fields of the DE and then use the Rows.Retrieve function to grab the data in the rows (you can use a filter to get only the rows you want). If you're good with javascript it's not hard to get the data you want (it comes back in JSON format). The documentation for the SSJS DE functions can be found here. If you're new to javascript post back and we can help you with some code examples or try to explain what the documentation shows.

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.