3

After digging, I have found the API object for FilterActivities, and have been able to Perform, Retrieve, etc. from them, but have been unable to Create one from scratch.

I have received the following error when running my script below:

{"message":"An error occurred when attempting to evaluate a SetObjectProperty function call. See inner exception for details." "description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a SetObjectProperty function call. See inner exception for details.
Error Code: OMM_FUNC_EXEC_ERROR
- from Jint -->

--- inner exception 1---
System.Exception: Invalid property name.
Object Type: ExactTarget.Integration.WSDL.DataExtension
Property Name: ObjectType - from OMMCommon"}

Below is my SSJS making the API call:

<script runat="server">

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


try {    
    // Data Extension Definitions
    var i = 0;
    var masterDE = '****';
    var onDeck = '****';
    // Initiate onDeckDE for Lookup
    var onDeckDE = DataExtension.Init(onDeck);


    // Gather all Rows from OnDeckDE
    var rows = onDeckDE.Rows.Lookup(["Status"], ["Active"]);

    // For Loop to create Filters from OnDeck

    if (rows !== null) {

        for (i in rows) {

    // Set Values for Row from OnDeck

            var filterName = rows[i].CampaignCode + '_alt';
            var campaignCode = rows[i].CampaignCode;
            var status = rows[i].Status;
            var macme = rows[i].MACME;
            var projectedDate = rows[i].ProjectedDate;


    // Retrieve the Filter Definition ObjectID for the Filter Activity Creation
            var RetrieveRequest = Platform.Function.CreateObject("RetrieveRequest");  
            Platform.Function.SetObjectProperty(RetrieveRequest, "ObjectType", "FilterDefinition");  
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "CustomerKey");
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "ObjectID");
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Name");

            var SimpleFilterPart = Platform.Function.CreateObject("SimpleFilterPart"); 
            Platform.Function.SetObjectProperty(SimpleFilterPart, "Property", "CustomerKey");
            Platform.Function.SetObjectProperty(SimpleFilterPart, "SimpleOperator", "equals"); 
            Platform.Function.AddObjectArrayItem(SimpleFilterPart, "Value", filterName);  
            Platform.Function.SetObjectProperty(RetrieveRequest, "Filter", SimpleFilterPart); 

            var s = [0,0];
            var FilterDefinition = Platform.Function.InvokeRetrieve(RetrieveRequest, s);

            var filterObjID = FilterDefinition[0].ObjectID;


    // Retrieve the Destination DE ObjectID for the Filter Activity Creation
            var RetrieveRequest = Platform.Function.CreateObject("DataExtension");  
            Platform.Function.SetObjectProperty(RetrieveRequest, "ObjectType", "DataExtension");  
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "CustomerKey");
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "ObjectID");
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Name");

            var SimpleFilterPart = Platform.Function.CreateObject("SimpleFilterPart"); 
            Platform.Function.SetObjectProperty(SimpleFilterPart, "Property", "CustomerKey");
            Platform.Function.SetObjectProperty(SimpleFilterPart, "SimpleOperator", "equals"); 
            Platform.Function.AddObjectArrayItem(SimpleFilterPart, "Value", filterName);  
            Platform.Function.SetObjectProperty(RetrieveRequest, "Filter", SimpleFilterPart); 

            var t = [0,0];
            var dataExtensionRR = Platform.Function.InvokeRetrieve(RetrieveRequest, t);

            var deObjID = dataExtensionRR[0].ObjectID;


    // Retrieve the Source DE ObjectID for the Filter Activity Creation
            var RetrieveRequest = Platform.Function.CreateObject("DataExtension");  
            Platform.Function.SetObjectProperty(RetrieveRequest, "ObjectType", "DataExtension");  
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "CustomerKey");
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "ObjectID");
            Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Name");

            var SimpleFilterPart = Platform.Function.CreateObject("SimpleFilterPart"); 
            Platform.Function.SetObjectProperty(SimpleFilterPart, "Property", "CustomerKey");
            Platform.Function.SetObjectProperty(SimpleFilterPart, "SimpleOperator", "equals"); 
            Platform.Function.AddObjectArrayItem(SimpleFilterPart, "Value", masterDE);  
            Platform.Function.SetObjectProperty(RetrieveRequest, "Filter", SimpleFilterPart); 

            var u = [0,0];
            var sourcedataExtensionRR = Platform.Function.InvokeRetrieve(RetrieveRequest, u);

            var sourcedeObjID = sourcedataExtensionRR[0].ObjectID;

// Build the Filter Activity
            var obj = Platform.Function.CreateObject("FilterActivity");
                    Platform.Function.SetObjectProperty(obj, "FilterActivityID", filterName);
                    Platform.Function.SetObjectProperty(obj, "FilterDefinitionID", FilterobjID);
                    Platform.Function.SetObjectProperty(obj, "DestinationObjectID", filterName);
                    Platform.Function.SetObjectProperty(obj, "SourceObjectID", sourcedeObjID);
                    Platform.Function.SetObjectProperty(obj, "CustomerKey", filterName);
                    Platform.Function.SetObjectProperty(obj, "Name", filterName);

            var p = [0,0];
            var CreateResults = Platform.Function.InvokeCreate(obj, p, null);

            var message = p[0];
            var errorCode = p[1];
            Write('<br />message: ' + message + '<br />errorCode: ' + errorCode + '<br />');            

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

Any idea what I am doing wrong? Judging from the sparse documentation on it, this should work...

  • The var RetrieveRequest = Platform.Function.CreateObject("DataExtension"); should be var RetrieveRequest = Platform.Function.CreateObject("RetrieveRequest"); -- in both instances. – Adam Spriggs Apr 22 at 17:39
2

Here's a working example of a CreateRequest for a FilterActivity from SSJS API Functions. The only difference I see between this and your code is you're not providing the Source and Destination Type IDs. In your case, these are both type 2 (Data Extension).

SSJS API CreateRequest - FilterActivity

<script runat="server">

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

    // Details of the new filter
    var ActivityName        = "FilterActivityAPI";
    var ActivityKey         = "FilterActivityAPI";

    // Source and Destination Types
    //      1 - Subscriber List, 2 - Data Extension, 3 - Group Wizard
    var SourceTypeID        = 2;
    var DestinationTypeID   = 2;

    // Object ID of the existing Filter Definition
    var FilterDefinitionID  = "cfc94cd4-1c0c-4bf9-b542-1d8e84957f14";

    // Object ID of Source Data Extension or List
    var SourceObjectID      = "33baae3e-b436-e711-80cb-1402ec723e3c";

    // Object ID of Destination Data Extension
    var DestinationObjectID = "0549fd10-7c6e-e711-80cb-1402ec723e3c";

    // API CreateRequest Code
    try {
        var activity = Platform.Function.CreateObject("FilterActivity");
        Platform.Function.SetObjectProperty(activity, "Name", ActivityName);
        Platform.Function.SetObjectProperty(activity, "CustomerKey", ActivityKey);
        Platform.Function.SetObjectProperty(activity, "SourceTypeID", SourceTypeID);
        Platform.Function.SetObjectProperty(activity, "DestinationTypeID", DestinationTypeID);
        Platform.Function.SetObjectProperty(activity, "FilterDefinitionID", FilterDefinitionID);
        Platform.Function.SetObjectProperty(activity, "SourceObjectID", SourceObjectID);
        Platform.Function.SetObjectProperty(activity, "DestinationObjectID", DestinationObjectID);

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

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

No Core library functions exist to do this by SSJS, but if you need to create filter activities in Business Units other than the one your script is executing in, the option to hand-roll your SOAP envelope and use HTTP.Post in a similar way to this example is open to you.

SOAP CreateRequest - FilterActivity

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
        <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <o:UsernameToken u:Id="uuid-88b91f91-bac2-489b-90fb-37e7b256e20c-1">
                <o:Username>{{Username}}</o:Username>
                <o:Password>{{Password}}</o:Password>
            </o:UsernameToken>
        </o:Security>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <Options></Options>
            <Objects xsi:type="FilterActivity">
                <Client>
                    <ID>123456</ID>
                </Client>
                <Name>FilterActivityAPI</Name>
                <CustomerKey>FilterActivityAPI</CustomerKey>
                <FilterDefinitionID>cfc94cd4-1c0c-4bf9-b542-1d8e84957f14</FilterDefinitionID>
                <SourceObjectID>33baae3e-b436-e711-80cb-1402ec723e3c</SourceObjectID>
                <DestinationObjectID>0549fd10-7c6e-e711-80cb-1402ec723e3c</DestinationObjectID>
                <DestinationTypeID>2</DestinationTypeID>
                <SourceTypeID>2</SourceTypeID>
            </Objects>
        </CreateRequest>
    </s:Body>
</s:Envelope>

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.