1

Say the table I'm working with has firstName and date as the only two column headers, with rows of data. Something like,

| firstName |    date    |
--------------------------
+ Robert    | 2018/01/01 +
+ Jenny     | 2018/01/01 +
+ George    | 2018/01/02 +
+ Richard   | 2018/01/02 +
+ Michael   | 2018/01/03 +
+ Sean      | 2018/01/03 +

I can extract the data itself with,

set @value = RequestParameter('someSearchKey')
set @data = LookupRows('myTable', 'value', @value)

And then loop through and print that data with,

%%[
    for @i = 1 to ROWCOUNT(@data) do 
        SET @ROW = ROW(@data, @i)
        SET @FIELD = FIELD(@ROW, 'firstName')
        ]%%
            <hr>
            %%=v(@FIELD)=%%
            <br>
        %%[
    next @i
]%%

Is there any way to lookup the headers and loop through them before looping through the data without using SSJS?

2 Answers 2

0

You should use the AMPScript API functions:

https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/invokeretrieve.htm

Something like :

%%[    
SET @rr = CreateObject("RetrieveRequest")  
SetObjectProperty(@rr, "ObjectType", "DataExtensionField")
AddObjectArrayItem(@rr,"Properties","Name")
AddObjectArrayItem(@rr,"Properties","CustomerKey")


SET @des = CreateObject("SimpleFilterPart")  
SetObjectProperty(@des, "Property", "CustomerKey")  
SetObjectProperty(@des, "SimpleOperator", "like")  
AddObjectArrayItem(@des, "Value", "2188FB40-E377-42D9-88AA-00BE621F9F9C")    
SetObjectProperty(@rr, "Filter", @des)

SET @de = InvokeRetrieve(@rr)  

FOR @c = RowCount(@de) DOWNTO 1  DO    
SET @row = Row(@de ,@c)     
SET @FName = Field(@row ,'Name')   
SET @DEKey = Field(@row ,'CustomerKey')

]%%
0

For any future viewers, I solved the problem with SSJS:

<script language="JavaScript" runat="server">
        //Load interface
        Platform.Load("Core","1.1");
        //copy and paste external key as a string below
        var DE_external_key = "some-32-digit-string";
        //initialize data extension (DE) with above external key
        var DE = DataExtension.Init(DE_external_key);
        //retrieve header (returns arrayList)
        var header = DE.Fields.Retrieve();
        //WRITE a required invisible 'anchor' for reference (LENGTH OF HEADER)
        Write('<p id="anchor" style="font-size:0px;">'+ header.length +'</p>');
        //WRITE a required invisible 'anchor' for reference (NAMES OF HEADERS with unique IDs)
        for (var q = 0; q < header.length; q++) {
            Write('<p id="_header' + q + '" style="font-size:0px;">' + header[q].Name + '</p>');
        }

</script>

Alternatively to WRITE in this context, you can use setValue and getValue

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .