---
schema_version: "1"
id: 04c08798fb4fd671a212531011e0cb7ba3cff926505066cd9e0ff6641792fc9b
title: Advanced Retrieves via WSProxy
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/guides/mc-programmatic-content/ssjs_WSProxy_advanced_retrieve.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_WSProxy_advanced_retrieve.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4da67e6855dd54859d90d3f51e83d137a531a376ae61132c3b24aeafdb2cf807
products:
  - Marketing Cloud Engagement APIs and Programmatic Languages
  - Marketing Cloud
---
# Advanced Retrieves via WSProxy

You can perform more complex retrieves, including the ability to set other properties on the retrieve request, including SOAP RetrieveOptions.

- The first three parameters are the same as the parameters in simple retrieves.
- The fourth parameter specifies the properties on the RetrieveOptions on the request.
- The fifth parameter specifies any remaining properties to set on the request. These properties include “QueryAllAccounts”, “RepeatLastResult”, “RepeatAllSinceLastBatch”, and so on.

```
var prox = new Script.Util.WSProxy();
var props = { QueryAllAccounts: true };
var cols = ["Name","CustomerKey","CategoryID","IsSendable"];
var filter = {
    Property: "CategoryID",
    SimpleOperator: "equals",
    Value: 101367
};
var opts = {
    BatchSize: 25
};
var data = prox.retrieve("DataExtension", cols, filter, opts, props);
```

## Pagination of Retrieves

To retrieve more pages, use the getNextBatch function.

- The first parameter is the object type.
- The second parameter is the RequestID from any previous retrieve.

This example loops through every email in an account and writes the Name property, then outputs the total number returned after outputting all of the items.

```
var prox = new Script.Util.WSProxy(),
    objectType = "Email",
    cols = ["Name"],
    moreData = true,
    reqID = null,
    numItems = 0;

while(moreData) {
    moreData = false;
    var data = reqID == null ?
           prox.retrieve(objectType, cols) :
           prox.getNextBatch(objectType, reqID);

    if(data != null) {
        moreData = data.HasMoreRows;
        reqID = data.RequestID;
        if(data && data.Results) {
            for(var i=0; i< data.Results.length; i++) {
                Platform.Response.Write(data.Results[i].Name);
                numItems++;
            }
        }
    }
}
Platform.Response.Write("<br />" + numItems + " total " + objectType);
```
