I'd like to retrieve ALL the queries in my current BU and return the results in a DE call "Queries". I've been reviewing a number of examples and pages on SS but haven't come across a simple Retrieve sample. Here's what I have so far
Updated to include revised code, including returning Target Data Extension name.
<script runat="server">
Platform.Load("core","1.1.5");
var prox = new Script.Util.WSProxy();
var cols = ["Name","CustomerKey","CategoryID","TargetUpdateType","CreatedDate","ModifiedDate","DataExtensionTarget.Name","Status"];
var data = prox.retrieve("QueryDefinition", cols)
var fields = [];
for (var i=0; i<data.Results.length; i++) {
fields.push({
name: data.Results[i].Name,
customerkey: data.Results[i].CustomerKey,
targetupdatetype: data.Results[i].TargetUpdateType,
createddate: data.Results[i].CreatedDate,
modifieddate: data.Results[i].ModifiedDate,
status: data.Results[i].Status,
DataExtensionTarget: data.Results[i].DataExtensionTarget.Name,
categoryID: data.Results[i].CategoryID
});
}
var de = DataExtension.Init('Queries');
var result = de.Rows.Add(fields);
Write("Result: " + result + " rows added");
}
catch (err) {
Write(Stringify(err));
}
</script>