I have the following SSJS function which uses WSProxy to return an array of all business units, however, when I test the script in a CloudPage, it returns an error.
I'm hoping someone can take a look at the prox.retrieve() i put together and let me know what I am missing.
<script runat="server">
Platform.Load("Core","1.1.5");
try{
var prox = new Script.Util.WSProxy(),
queryAllAccounts = true,
objectType = "Account",
cols = ["ID","Name"],
data = prox.retrieve(objectType, cols, queryAllAccounts)
fields = [];
for (var i=0; i<data.Results.length; i++) {
fields.push({
ID: data.Results[i].ID,
name: data.Results[i].Name
});
}
var de = DataExtension.Init('BusinessUnitDetails');
var result = de.Rows.Add(fields);
Write("Result: " + result + " rows added")
}
catch (err) {
Write("Error Message: " + Stringify(err.message) + Stringify(err.description));
}
</script>