4

I currently have this SOAP api request with two simple filter parts:

<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Header>
        <fueloauth xmlns="http://exacttarget.com">***************</fueloauth>
    </Header>
    <Body>
        <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <RetrieveRequest>
                <ObjectType>ListSubscriber</ObjectType>
                <Properties>CreatedDate</Properties>
                <Properties>Client.ID</Properties>
                <Properties>SubscriberKey</Properties>
                <Properties>Status</Properties>
                <Properties>UnsubscribedDate</Properties>
                <Properties>ID</Properties>
                <Properties>Client.PartnerClientKey</Properties>
                <Filter xsi:type="ComplexFilterPart" >
                  <LeftOperand xsi:type="SimpleFilterPart">
                    <Property>ListID</Property>
                    <SimpleOperator>equals</SimpleOperator>
                    <Value>100</Value>
                  </LeftOperand>
                  <LogicalOperator>AND</LogicalOperator>
                  <RightOperand xsi:type="SimpleFilterPart">
                    <Property>ModifiedDate</Property>
                    <SimpleOperator>between</SimpleOperator>
                    <DateValue>2014-11-30T10:30:50.092-05:00</DateValue>
                    <DateValue>2014-12-17T10:30:50.122-05:00</DateValue>
                  </RightOperand>
                </Filter>
            </RetrieveRequest>
        </RetrieveRequestMsg>
    </Body>
</Envelope>

I want to add a third filter for Status == Active. How would I do that? Is it even possible?

1 Answer 1

4

You can combine ComplexFilterParts or you can using the AdditionalOperand property on the ComplexFilterPart object. There's an example at the bottom of this this page.

<Filter xsi:type="ComplexFilterPart">
    <LeftOperand xsi:type="SimpleFilterPart">
        <Property>SendID</Property>
        <SimpleOperator>equals</SimpleOperator>
        <Value>10980375</Value>
    </LeftOperand>
    <LogicalOperator>AND</LogicalOperator>
    <RightOperand xsi:type="SimpleFilterPart">
        <Property>BatchID</Property>
        <SimpleOperator>equals</SimpleOperator>
        <Value>5</Value>
    </RightOperand>
    <AdditionalOperands>
        <Operand xsi:type="SimpleFilterPart">
            <Property>SubscriberID</Property>
            <SimpleOperator>equals</SimpleOperator>
            <Value>199672583</Value>
        </Operand>
    </AdditionalOperands>
</Filter>

UPDATE: Here's a nested ComplexFilterPart example (from a DataExtensionObject retrieve):

<Filter xsi:type="ComplexFilterPart">
   <LeftOperand xsi:type="ComplexFilterPart">
      <LeftOperand xsi:type="SimpleFilterPart">
         <Property>EmailAddress</Property>
         <SimpleOperator>equals</SimpleOperator>
         <Value>[email protected]</Value>
      </LeftOperand>
      <LogicalOperator>AND</LogicalOperator>
      <RightOperand xsi:type="SimpleFilterPart">
         <Property>InsertDate</Property>
         <SimpleOperator>lessThan</SimpleOperator>
         <DateValue>2015-01-23T10:12:21</DateValue>
      </RightOperand>
   </LeftOperand>
   <LogicalOperator>AND</LogicalOperator>
   <RightOperand xsi:type="SimpleFilterPart">
      <Property>_CustomObjectKey</Property>
      <SimpleOperator>equals</SimpleOperator>
      <Value>260239</Value>
   </RightOperand>
   <AdditionalOperands />
</Filter>

UPDATE: Here's a WSProxy snippet that illustrates how you might construct a multiple AND conditional. This one is for a customer service lookup page that I built in CloudPages:

var prox = new Script.Util.WSProxy();
var objectType = "DataExtensionObject[" + deExternalKey + "]";
var cols = ["EmailAddress", "FirstName", "LastName", "AccountNumber", "PLU", "CompanyCode", "subjectLine", "dateSent", "emailStatus", "recordID", "arrivalStatus", "failureReason", "totalOpens", "uniqueOpens", "openTime"];

var sfp_em = {Property: "EmailAddress",   SimpleOperator: "like",       Value: email};
var sfp_fn = {Property: "FirstName",      SimpleOperator: "like",       Value: firstName};
var sfp_ln = {Property: "LastName",       SimpleOperator: "like",       Value: lastName};
var sfp_an = {Property: "AccountNumber",  SimpleOperator: "equals",     Value: accountNumber};
var sfp_pl = {Property: "PLU",            SimpleOperator: "equals",     Value: plu};
var sfp_cc = {Property: "CompanyCode",    SimpleOperator: "equals",     Value: cmpCd};
var sfp_df = {Property: "dateSent",       SimpleOperator: "greaterThan",Value: dateFrom};
var sfp_dt = {Property: "dateSent",       SimpleOperator: "lessThan",   Value: dateTo};

var filter = [];

// dates are always present
filter = {LeftOperand: sfp_df, LogicalOperator: "AND", RightOperand: sfp_dt};

if (email) {
  filter = {LeftOperand: filter, LogicalOperator: "AND", RightOperand: sfp_em};
}

if (firstName) {
  filter = {LeftOperand: filter, LogicalOperator: "AND", RightOperand: sfp_fn};
}

if (lastName) {
  filter = {LeftOperand: filter, LogicalOperator: "AND", RightOperand: sfp_ln};
}

if (accountNumber) {
  filter = {LeftOperand: filter, LogicalOperator: "AND", RightOperand: sfp_an};
}

if (plu) {
  filter = {LeftOperand: filter, LogicalOperator: "AND", RightOperand: sfp_pl};
}

if (cmpCd) {
  filter = {LeftOperand: filter, LogicalOperator: "AND", RightOperand: sfp_cc};
}

// if no fields are filled in, return no rows
if (email == ""  && firstName == "" && lastName == "" && accountNumber == "" && plu == "" && cmpCd == "") {
   filter = {Property: "EmailAddress",  SimpleOperator: "equals", Value: "null"};
}

var opts = { BatchSize: 500 };
var reqID = null;

var data = reqID == null ? prox.retrieve(objectType, cols, filter, opts, props) : prox.getNextBatch(objectType, reqID);
6
  • Thanks for your response. However, it's not working. The Additional Operand gets ignored. I've tried swapping the filters around and sure enough whatever is defined as the Additional Operand gets ignored. Commented Feb 19, 2015 at 14:36
  • Aaand AdditionalOperands only works with certain Objects. Best bet is to nest ComplexFilterParts. Updated my example above. Commented Feb 19, 2015 at 15:50
  • I appreciate the help. That works perfectly. I did have to play around with the ordering of the filters. I got it to work with List Id first, Status second and then the date filter last. Commented Feb 19, 2015 at 19:07
  • This was extremely helpful to me as well. Any idea how this might look with 5 filters? I guess you'd just have to keep nesting? Commented Dec 31, 2018 at 15:45
  • 1
    I've added an example implementation to my answer. Commented Dec 31, 2018 at 16:09

You must log in to answer this question.

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