Currently I am grabbing all of my public lists from Marketing Cloud and printing them out on the page, but I want to be able to print these out in a table format on the page, maybe by possibly using a for loop within the HTML. I have tried to do the for loop but it did not work.

Is there a way to print out these lists within a tag or something of the sort by possibly using AMPscript or something along the lines of that?

Here is my SSJS code:

<script type="text/javascript" runat="server">

Platform.Load("core", "1.1.1");

var debug = false;
var request = {};
SetVar("urlThis", Platform.Request.RequestURL);

if (Request.Method == "GET") {

    if (debug) {

  Variable.SetValue("@email", Request.GetQueryStringParameter("cm_lm"))

} else if (Request.Method == "POST") {

    if (debug) {


function SetVar(varName, varValue){
    request[varName] = varValue;
    Variable.SetValue(varName, varValue);

function isEmpty(str) {
  return (!str || 0 === str.length);
if (debug) {
    Write("<br><br>debug output: " + Stringify(request));

  function getAllLists(mid) {

  var rr = Platform.Function.CreateObject("RetrieveRequest");
  Platform.Function.SetObjectProperty(rr, "ObjectType", "List");

  Platform.Function.AddObjectArrayItem(rr, "Properties", "ID");
  Platform.Function.AddObjectArrayItem(rr, "Properties", "ListName");
  Platform.Function.AddObjectArrayItem(rr, "Properties", "Description");

  var filter1 = Platform.Function.CreateObject("SimpleFilterPart");
  Platform.Function.SetObjectProperty(filter1, "Property", "Type");
  Platform.Function.SetObjectProperty(filter1, "SimpleOperator", "equals");
  Platform.Function.AddObjectArrayItem(filter1, "Value", "Public");

  var filter2 = Platform.Function.CreateObject("SimpleFilterPart");
  Platform.Function.SetObjectProperty(filter2, "Property", "ListClassification");
  Platform.Function.SetObjectProperty(filter2, "SimpleOperator", "notEquals");
  Platform.Function.AddObjectArrayItem(filter2, "Value", "PublicationList");

  var cfp = Platform.Function.CreateObject("ComplexFilterPart");
  Platform.Function.SetObjectProperty(cfp, "LeftOperand", filter1);
  Platform.Function.SetObjectProperty(cfp, "LogicalOperator", "AND");
  Platform.Function.SetObjectProperty(cfp, "RightOperand", filter2);

  Platform.Function.SetObjectProperty(rr, "Filter", cfp);

  var clid = Platform.Function.CreateObject("ClientID");
  Platform.Function.SetObjectProperty(clid, "ID", mid);
  Platform.Function.AddObjectArrayItem(rr, "ClientIDs", clid);

  var reqParams = [0, 0];
  var Lists = Platform.Function.InvokeRetrieve(rr, reqParams);

  return Lists;

  var allPublicationLists = getAllLists(100008610);
    for (var i in allPublicationLists) {
      Write("\n" +allPublicationLists[i]["ListName"] + "|" 



2 Answers 2


You already have pretty much everything you need. See below snippet from your code that would need to be changed:

<script runat=server>

    return Lists;

var allPublicationLists = getAllLists(100008610);  


<script runat=server>
   for (var i in allPublicationLists) {

        if (i = 1) {

          Write("<table>" + "\n");


        Write("<tr><td>" +allPublicationLists[i]["ListName"] + "</td><td>" +allPublicationLists[i]["Description"] + "</td></tr>" + "\n");

        if (i = allPublicationLists.length) {

            Write("\n" + "</table>");



This will output HTML inside the for loop. Adding the table tag only on first run, then rows and data cells on each run through and finally on the last run through it will add a closing table tag.

You will need to add whatever styling and attributes you want, but this should allow you to set up inside of a table.

You can also add a 'write' to add the HTML and Body open/close inside the For Loop as well, but I usually like to keep them separate in case other content needs to be added.

  • Is this able to be put within a <html> tag under a <script> tag? I tried doing something similar to this and it just didn't seem to work. Jun 12, 2018 at 14:19
  • yes. I will edit to show example. Jun 12, 2018 at 14:23
  • 1
    Awesome! That seemed to work. Pretty sure I just forgot to add the runat=server part to the script tag.. but anyways! Jun 12, 2018 at 14:29

the response from Gortonington look great, just one this if if (i = 1) should be if (i == 1)

and also

(i = allPublicationLists.length) should be (i == allPublicationLists.length)

because its doing assignment instead of expected comparision

You must log in to answer this question.

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