2

The Salesforce documentation provides helpful examples of creating regular data extensions using SSJS, but no example for creating a filtered one. Does anyone have a code sample for creating a filtered data extension? I'm unsure of the syntax that would need to be used. Thanks!

2 Answers 2

1

I've done this with WSProxy:

<script runat="server">

  Platform.Load("Core","1");

  var prox = new Script.Util.WSProxy();
  var filterName = "TestFilter"
  var filterSourceDEKey = "TestDEKey"
  var filterCategoryId = 1234 // folder in which to create the filter 
  var DEFieldVal1 = "whee"
  var DEFieldVal2 = "whoa"

  var sfp1 = {"__Type__": "SimpleFilterPart", Property: "DEField1", SimpleOperator: "equals", Value: [DEFieldVal1]};
  var sfp2 = {"__Type__": "SimpleFilterPart", Property: "DEField2", SimpleOperator: "equals", Value: [DEFieldVal2]};
  var cfp = {
                "__Type__": "ComplexFilterPart"
              , LeftOperand: sfp1
              , LogicalOperator: "AND"
              , RightOperand: sfp2
            };

  var filterDefinition = {
       "Name": filterName
     , "CustomerKey" : filterName
     , "DataSource" : { "__Type__": "DataExtension", "CustomerKey" : filterSourceDEKey }
     , "DataFilter" : cfp // you can also just use a SimpleFilterPart here instead of a complex one
     , "CategoryID" : filterCategoryID
  };

  var result = prox.createItem("filterDefinition", filterDefinition);

  if (debug) {
    Write("<br>result: " + Stringify(result));
  }

</script>
3
  • nice. Didn't know that. Another piece of related info: If you need a data extension that is populated by a filter activity, not manually refreshed, you can just create a normal DE and reference it in the filter activity (which can be created via API). The data extension will not show as "filtered", but when referenced in the filter activity, it acts as if. Meaning that the Data Extension fields change if the Source Data Extension of the filter changes upon filter refresh. Which is quite handy in case your source DE gets new fields and the dependent DEs automatically adapt. Commented Dec 1, 2021 at 16:05
  • This was part of a larger solution to automatically refresh segments from a master by retail store. Coupled with a meaningful naming scheme, it sure reduced the LOE for targeting. Commented Dec 1, 2021 at 18:37
  • Problem with it is, IIRC, that you can only select one filtered data source in the send definition. I have a query version of this that is more flexible. Commented Dec 1, 2021 at 18:39
0

Filtered data extension comes from the main data extension from which you want to filter a data. I don't think you need ssjs to create a filtered data extension. You can simply click on create in DE and from the type of DE choose filtered DE and the source DE you want to filter it from. You filtered DE will be created.

2
  • 2
    Thanks, but I'm interested in creating a script to automate needed data extensions (regular and filtered). From what I can see, a filter definition (SOAP API) specifying the source DE may be what I need.
    – Glen Mazza
    Commented Mar 6, 2017 at 1:50
  • I need the same answer. were you able to finish this task? Commented Jan 22, 2018 at 15:12

You must log in to answer this question.

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