Lazy mans WSProxy retrieve all

Charlie Fay
2 min readMay 2, 2022

--

The WSProxy() object offers several retrieve options, depending on the level of complexity you need. The simplest option takes the type of object as the first parameter, and an array of object property names to retrieve.

var prox = new Script.Util.WSProxy(); 
var cols = ["Name", "CustomerKey", "CategoryID", "IsSendable"];
var data = prox.retrieve("DataExtension", cols);

Having to include a “cols” array with the fields we’d like to retrieve can be a little burdening, especially during initial stages of development or early exploration of a solution. In this post I’m sharing a little trick that you can use to get all fields without having to write them out initially.

The setup is one extra “describe” call that we make with WSProxy. You can then traverse the API response and build out an array of Property Names that are retrievable. Take this array and use in your subsequent retrieve request.

Describe

var soapObject = "DataExtension";
var describe = prox.describe(soapObject);
var colsArr = [];
for (var i=0; i<describe.Results[0].Properties.length; i++) {
if (describe.Results[0].Properties[i].IsRetrievable) {
colsArr.push(describe.Results[0].Properties[i].Name);
};
};

Retrieve

With our array built out, the subsequent retrieve request could look something like the below:

var deName = "Onboarding Journey";
var filter = {"Property": "Name", "SimpleOperator": "equals", "Value": deName};
var data = prox.retrieve(soapObject, colsArr, filter);
Write(Stringify(data));

This is a useful technique to get all the fields we need during our initial build. It would be recommended to remove the describe request and hard code the required fields once you know what can be retrieved and what you need for your solution.

See also:

--

--

Charlie Fay
Charlie Fay

Written by Charlie Fay

I write about Salesforce Marketing Cloud, Marketing Automation, Development and Programmatic Languages. I enjoy solving complex problems with simplicity.

No responses yet