3

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>

1 Answer 1

1

Your retrieve function has too many parameters. Assuming you need just the current BU and that you have 3 fields in your "Queries" DE for "name", "customerkey" and "categoryID".

<script runat="server">
    Platform.Load("core","1.1.5");
    var prox = new Script.Util.WSProxy();
    var cols = ["Name","CustomerKey","CategoryID"];
    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,
            categoryID: data.Results[i].CategoryID
        });
    }
    var de = DataExtension.Init('Queries');
    var result = de.Rows.Add(fields);        
    Write("Result: " + result + " rows added");
</script>
1
  • Wow I wasn't even close. That worked like a charm. Thank you so much! Commented Jun 19, 2019 at 13:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .