I am trying to use a script activity to update a data extension with the statuses of subscriber records. I have managed to get the code working but it will only add 2500 records. I have been reading about retrieving the OverallStatus to see if it produces the value "MoreDataAvailable". From the link below, I can see that you can use the retrieve method to do this.
http://help.exacttarget.com/en-US/technical_library/web_service_guide/methods/retrieve/
There's also mention of a ContinueRequest method call. I can't find any documentation that mentions if this could be used with SSJS.
Is it possible to retrieve more than 2500 records with SSJS? Am I on the right track with the code below?
<script runat="server">
Platform.Load("core","1");
try {
var myList = List.Init('All Subscribers');
subs = myList.Subscribers.Retrieve({Property:"Status",SimpleOperator:"equals",Value:"Unsubscribed"});
var MasterPublicationList = DataExtension.Init("MasterPublicationList");
do {
var status = subs.Retrieve(rr);
//write to data extension
for (var i = 0; i < subs.length; i++) {
var subkeyUnsub = subs[i].SubscriberKey;
MasterPublicationList.Rows.Add({"Subscriber Key":subkeyUnsub,"Publication":"New Publication name","IsSubscribed":"False"});
}
var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr,"ContinueRequest",RequestID);
}while(status.OverallStatus == "MoreDataAvailable")
} catch (ex) {
Write("An error has occurred: " + Stringify(ex));
}
</script>
The error message I get is:
An error has occurred: {"message":"Object expected: Retrieve","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(VariableDeclarationStatement statement)\r\n at Jint.Expressions.VariableDeclarationStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: Retrieve\r\nException of type 'Jint.Native.JsException' was thrown. – from Jint\r\n\r\n"}
Many thanks!
Best Answer
The underlying technology has put a limit on number of rows, and SSJS is not directly able to get all the records, it would seem.
In order to do what you want, you should actually be using a Query Activity and utilize the
_subscribers
system data view.Here is the link to the query activity documentation
Queries are basic SQL to access your data extensions, and list data.
Your query might look something like this edited for real world solution
In the query activity - you would select your target data extension. You can perform pretty much any normal SQL function, like joins, nested selects, etc.