Skip to main content
Tweeted twitter.com/StackSalesforce/status/1146660022191099904
I've updated the script to include other Query params, including the Target Data Extension name.
Source Link

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 props = { QueryAllAccounts: true };
var cols = ["Name","CustomerKey","CategoryID"];

"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, 
 filter           customerkey: data.Results[i].CustomerKey, 
 opts           targetupdatetype: data.Results[i].TargetUpdateType, 
 props           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>

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

var prox = new Script.Util.WSProxy();
var props = { QueryAllAccounts: true };
var cols = ["Name","CustomerKey","CategoryID"];


var data = prox.retrieve("QueryDefinition", cols, filter, opts, props);

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>
Source Link

WSProxy to Retriever All QueryDefinitions in Marketing Cloud

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

var prox = new Script.Util.WSProxy();
var props = { QueryAllAccounts: true };
var cols = ["Name","CustomerKey","CategoryID"];


var data = prox.retrieve("QueryDefinition", cols, filter, opts, props);