0

I faced strange situation. I am trying to retrieve all Data Filters from the specific Business Unit from salesforce Marketing Cloud.

on the marketing cloud SDK help page there is info that filterDefinition object has property as "Client" enter image description here

I need to do the documentation and also list all the Data filters from specific BU. this is my code. without part of the "Client" property is working, downloading all the Data filters in the system to the target Data Extension, which is not helping because I need to filter them somehow to achieve specific list for specific BU.

<script runat=server>
Platform.Load("Core","1.1.1");

var prox = new Script.Util.WSProxy(); // Sets the Proxy - DO NOT CHANGE

var custKey = "xxx-xxxx-xxxxx-xxxxx";     
var logDE = DataExtension.Init(custKey);


 var cols  = ["Name","CustomerKey","Client"];
 var reqID = null
 var moreData = true;
 var desc = [];

while(moreData) {
moreData = false;
var data = reqID == null ?
  prox.retrieve("FilterDefinition", cols) : 
  prox.getNextBatch("FilterDefinition", reqID);

 if(data != null) {
  moreData = data.HasMoreRows;
  reqID = data.RequestID;
  if(data && data.Results) {
    for (var i = 0; i < data.Results.length; i++) {

    var name =data.Results[i].Name
    var clientid =data.Results[i].Client
    var customerkey = data.Results[i].CustomerKey
                      

                    logDE.Rows.Add({
                        CustomerKey: customerkey,
                        Name: name,
                        ClientID: clientid
                        
                    });
                    
         }          
    }
  }
}

I would really appreciate the help with this case. I looked I think everywhere trying to find FilterDefinition property which will contains the Business Unit ID.

Regards!.

0

1 Answer 1

1

Your code does not populate ClientID because you are retrieving the property incorrectly in 2 places, that how it should be:

  1. var cols = ["Name", "CustomerKey", "Client.ID"];
  2. var clientid = data.Results[i].Client.ID

This will start populating the Data Extension's field correctly but with only the Business Unit's MID that you are running this script on. To achieve retrieval across the whole account, you will need to update your code further and end result will look like that -

<script runat="server">
Platform.Load("Core","1");

var prox = new Script.Util.WSProxy();
try{

    var custKey = "xxx-xxxx-xxxxx-xxxxx";
    var logDE = DataExtension.Init(custKey);


    var cols  = ["Name","CustomerKey","Client.ID"];
    var options  = {IncludeObjects: true};
    var props    = {QueryAllAccounts: true};
    var reqID    = null
    var moreData = true;
    var desc     = [];

    while(moreData) {
        moreData = false;
        var data = reqID == null ?
        prox.retrieve("FilterDefinition", cols, filter, options, props) : 
        prox.getNextBatch("FilterDefinition", reqID);

        if(data != null) {
            moreData = data.HasMoreRows;
            reqID = data.RequestID;
            if(data && data.Results) {
                for (var i = 0; i < data.Results.length; i++) {

                    var name = data.Results[i].Name
                    var clientid = data.Results[i].Client.ID
                    var customerkey = data.Results[i].CustomerKey

                    logDE.Rows.Add({
                        CustomerKey: customerkey,
                        Name: name,
                        ClientID: clientid
                        
                    });
                                    
                }          
            }
        }
    }

} catch (e) {
    Write(Stringify(e));
}
</script>

In short, I have added 2 more parameters for advanced retrieval. You will need to run this on the Parent level.

You must log in to answer this question.

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