0

I need to create a list of Data Extensions being used in the Filter Activities in Salesforce Marketing Cloud. I tried using the FilterDefinition but I am not getting any results. I am using the following code:

<script runat="server">
    Platform.Load("Core", "1");
    try {
    //initiate WSProxy
    var prox = new Script.Util.WSProxy();
    //initiate data extension
    var targetDE = 'xxxxxxx-xxxxxxx-xxxxxxxxx'; //pass external key of the target DE
    var logDE = DataExtension.Init(targetDE);

    function getFilters(objectType, cols) {
        var objectType = "FilterDefinition",
    cols = ["DestinationObject.ObjectID", "Description", "Name", "ObjectID"],
    moreData = true,
    reqID = null,
    numItems = 0;
    while (moreData) {
        moreData = false;
    var data = reqID == null ? prox.retrieve(objectType, cols) : prox.getNextBatch(objectType, reqID);
    if (data != null) {
        moreData = data.HasMoreRows;
    reqID = data.RequestID;
    if (data && data.Results) {
                    for (var i = 0; i < data.Results.length; i++) {
                        if (data.Results[i].DestinationObject.ObjectID) {
                            var cols = ["Name", "CustomerKey", "ObjectID"];
    var filter = {
        Property: "ObjectID",
    SimpleOperator: "equals",
    Value: data.Results[i].DestinationObject.ObjectID
                            };
    var deName = prox.retrieve("DataExtension", cols, filter);
    if (deName.Results[0].Name) {
        logDE.Rows.Add({
            DEName: deName.Results[0].Name,
            DEKey: deName.Results[0].CustomerKey,
            ActivityName: data.Results[i].Name,
            ActivityType: "Filter",
            ActivityDescription: data.Results[i].Description
        });
                            }
                        }
    numItems++;
                    }
                }
            }
        }
    Write("<br />" + numItems + " total " + objectType + "<br>");
    }
        getFilters(objectType, cols)
} catch (e) {
            Write(Stringify(e));
}
</script> 

1 Answer 1

4

First, FilterDefinitions and FilterActivity are two different things.

If you want FilterDefinition source Data Extension information, you need to use DataSource.ObjectID instead of DestinationObject.ObjectID. This will retrieve the FilterDefinition DE info:

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

    var prox = new Script.Util.WSProxy();
    var objectType = "FilterDefinition";
    var cols = ["DataSource.ObjectID", "Description", "Name", "ObjectID"]
    var moreData = true;
    var reqID = null;
    var numItems = 0;

    while (moreData) {

        moreData = false;
        var data = reqID == null ? prox.retrieve(objectType, cols) : prox.getNextBatch(objectType, reqID);

        if (data != null) {

            moreData = data.HasMoreRows;
            reqID = data.RequestID;

            if (data && data.Results) {

                for (var i = 0; i < data.Results.length; i++) {

                    if (data.Results[i].DataSource.ObjectID) {

                        var cols2 = ["Name", "CustomerKey", "ObjectID"];
                        var filter2 = {
                            Property: "ObjectID",
                            SimpleOperator: "equals",
                            Value: data.Results[i].DataSource.ObjectID
                        };

                        var deName = prox.retrieve("DataExtension", cols2, filter2);

                        if (deName.Results[0].Name) {
                            Write("<br>deName.Results[0].Name: " + deName.Results[0].Name)

                        }
                    }
                    numItems++;
                } 
            }
        }
    }

    Write("<br>" + numItems + " total " + objectType);

} catch (e) {

    Write("<br>e: " + Stringify(e));

}
</script> 

For FilterActivity, the retrievable properties are:

  • Client.ID
  • CreatedDate
  • CustomerKey
  • DefinitionObjectID
  • Description
  • DestinationObjectID
  • DestinationTypeID
  • ModifiedDate
  • Name
  • ObjectID
  • SourceObjectID
  • SourceTypeID
  • StatusID

To retrieve FilterActivity, you'd need to adjust your script like this:


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

    var prox = new Script.Util.WSProxy();
    var objectType = "FilterActivity";
    var cols = ["DestinationObjectID", "DestinationTypeID"]
    var moreData = true;
    var reqID = null;
    var numItems = 0;

    while (moreData) {

        moreData = false;
        var data = reqID == null ? prox.retrieve(objectType, cols) : prox.getNextBatch(objectType, reqID);

        if (data != null) {

            moreData = data.HasMoreRows;
            reqID = data.RequestID;

            if (data && data.Results) {

                for (var i = 0; i < data.Results.length; i++) {

                    if (data.Results[i].DestinationObjectID) {

                        var cols2 = ["Name", "CustomerKey", "ObjectID"];
                        var filter2 = {
                            Property: "ObjectID",
                            SimpleOperator: "equals",
                            Value: data.Results[i].DestinationObjectID
                        };

                        var deName = prox.retrieve("DataExtension", cols2, filter2);

                        if (deName.Results[0].Name) {
                            Write("<br>deName.Results[0].Name: " + deName.Results[0].Name)

                        }
                    }
                    numItems++;
                } 
            }
        }
    }

    Write("<br>" + numItems + " total " + objectType);

} catch (e) {

    Write("<br>e: " + Stringify(e));

}
</script> 
1
  • Thanks @AdamSpriggs! It worked!
    – pmleal07
    Commented Apr 19, 2023 at 9:58

You must log in to answer this question.

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