Here's the SSJS function that I use to retrieve all of the Publication Lists. While it's not AMPscript, it can be translated:
function getAllPublicationLists() {
var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "Publication");
Platform.Function.SetObjectProperty(rr, "QueryAllAccounts", "True");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Name");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Category");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Client.ID");
var reqParams = [0,0];
var publications = Platform.Function.InvokeRetrieve(rr, reqParams);
return publications;
}
If you just want the Public ones, here's a function for that:
function getAllPublicPublicationLists(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", "equals");
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;
}
To output them, you can iterate through the results like this:
var allPublicationLists = getAllPublicationLists();
for (var i in allPublicationLists) {
Write("\n" + allPublicationLists[i]["ID"] + "|" +allPublicationLists[i]["Client"]["ID"] + "|" +allPublicationLists[i]["Name"]);
}
Then if you wanted to retrieve all of a subscriber's publications, then you can do something like this with the API Objects:
function getSubscriberLists(subscriberkey) {
var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "ListSubscriber");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ListID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "SubscriberKey");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");
var filter = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(filter, "Property", "SubscriberKey");
Platform.Function.SetObjectProperty(filter, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(filter, "Value", subscriberkey);
Platform.Function.SetObjectProperty(rr, "Filter", filter);
var reqParams = [0,0];
var subscriberLists = Platform.Function.InvokeRetrieve(rr, reqParams);
return subscriberLists;
}
If you wanted to just get non-Publication lists:
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;
}