1

I have hit a bit of a wall in this. I can create Filter Definitions via the SSJS function and via SSJS and AMPscript and SOAP API calls, but every time I try to create via WSProxy, I get the same error on the 'DataFilter' part of the payload.

  1. I verified it is not an array it throws the error:
    Object of type 'System.Collections.ArrayList' cannot be converted to type 'ExactTarget.Integration.WSDL.FilterPart'.
  2. I have checked the SOAP objects and 'FilterPart' Object is not an actual object, but instead an abstract base class for the subsets of Objects under it. Such as SimpleFilterPart, ComplexFilterPart, and TagFilterPart
  3. To keep things simple, I attempted to create a SimpleFilterPart (no pun intended). But if I put it through as an object, using the {Property:"", SimpleOperator:"", Value:""} format same as the SOAP object/envelope, it throws the error:
    Invalid property name: Property
  4. I attempted to do a retrieve on this via SSJS Function it came back with the following in DataFilter
    "DataFilter":"ExactTarget.Integration.WSDL.ComplexFilterPart"
  5. I have tried deconstructing it via results[0].DataFilter[i] or guessing on property names - results[0].DataFilter.Property etc. and either it ends up null or gives junk results.
  6. Pulling a Retrieve Request via WSProxy returns "DataFilter":null despite having this column listed in the retrieve. This is true of Complex or Simple Filters.

I have run out of ideas on how to do this or other avenues to explore to find a solution. Anyone have any ideas?

Below is an example of my current code:

<script runat=server>
var prox = new Script.Util.WSProxy();

  var filterDefinition = {
         Name: "filterName"
       , CustomerKey : "filterName"
       , DataSource : {"CustomerKey" : "FilterSource_API" }
       , DataFilter : {Property: "MyField", SimpleOperator: "equals", Value: "MyValue"} 
  };
try {
  var results = prox.createItem("FilterDefinition", filterDefinition);

  Platform.Response.Write(Platform.Function.Stringify(results));
} catch(e) {
  Platform.Response.Write(Platform.Function.Stringify(e));
}

</script>
3

I gave up and did it with the API functions:

var sfp1 = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(sfp1, "Property", "ID");
Platform.Function.SetObjectProperty(sfp1, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(sfp1, "Value", "111");

var sfp2 = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(sfp2, "Property", "Status");
Platform.Function.SetObjectProperty(sfp2, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(sfp2, "Value", "Active");

var filterObj = Platform.Function.CreateObject("ComplexFilterPart");
Platform.Function.SetObjectProperty(filterObj, "LeftOperand", sfp1);
Platform.Function.SetObjectProperty(filterObj, "LogicalOperator", "AND");
Platform.Function.SetObjectProperty(filterObj, "RightOperand", sfp2);

var dataSource = Platform.Function.CreateObject('DataExtension');
Platform.Function.SetObjectProperty(dataSource, "CustomerKey", filterSourceDEKey);

var filterDef = Platform.Function.CreateObject("FilterDefinition");
Platform.Function.SetObjectProperty(filterDef, "CategoryID", "12345");
Platform.Function.SetObjectProperty(filterDef, "Name", "filterName");
Platform.Function.SetObjectProperty(filterDef, "CustomerKey", "filterName");
Platform.Function.SetObjectProperty(filterDef, "DataSource", dataSource);
Platform.Function.SetObjectProperty(filterDef, "DataFilter", filterObj);

var result = [0,0];
var status = Platform.Function.InvokeCreate(filterDef, result, null);
var message = result[0];
var errorCode = result[1];   

Update:

Here's how to do it with WSProxy:

var sfp1 = {"__Type__": "SimpleFilterPart", Property: "ID", SimpleOperator: "equals", Value: [ID]};
var sfp2 = {"__Type__": "SimpleFilterPart", Property: "Status", SimpleOperator: "equals", Value: ["Active"]};
var cfp = {
              "__Type__": "ComplexFilterPart"
            , LeftOperand: sfp1
            , LogicalOperator: "AND"
            , RightOperand: sfp2
          };

var filterDefinition = {
   "Name": filterName
   , "CustomerKey" : filterName
   , "DataSource" : { "__Type__": "DataExtension", "CustomerKey" : filterSourceDEKey }
   , "DataFilter" : cfp
   , "CategoryID" : filterCategoryID
};

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

(h/t to a certain someone who shall remain nameless -- thank you!)

  • 1
    yeah, I agree the other options work and are viable alternatives, I more or less just am trying to find out what the issue is and how to solve for it. Especially if it can lead to further insight into translating SOAP into WSProxy JSON. – Gortonington Apr 26 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.