Created
          October 31, 2019 18:28 
        
      - 
      
- 
        Save zuzannamj/019d8925c9f2440c39335463be5ce55e to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <script runat="server"> | |
| Platform.Load("core","1.1"); | |
| try{ | |
| //Set time range of retrieved tracking data | |
| var filter = { | |
| Property: "EventDate", | |
| SimpleOperator: "between", | |
| Value: ["2016-01-01T00:00:00.000Z", "2017-10-30T00:00:00.000Z"] | |
| }; | |
| //Set Data Extension properties | |
| var fields = [ | |
| { "Name" : "SendID", "FieldType" : "Number"}, | |
| { "Name" : "SubscriberKey", "FieldType" : "Text", "MaxLength" : 50 }, | |
| { "Name" : "EventDate", "FieldType" : "Date", "Ordinal" : 2 }, | |
| { "Name" : "EventType", "FieldType" : "Text", "MaxLength" : 50 }, | |
| { "Name" : "TriggeredSendDefinitionObjectID", "FieldType" : "Text", "MaxLength" : 50 }, | |
| { "Name" : "BatchID", "FieldType" : "Number"}, | |
| { "Name" : "ClientID", "FieldType" : "Number"} | |
| ] | |
| var UnsubEventDE = { | |
| "CustomerKey" : "05_UnsubEvent", | |
| "Name" : "05_UnsubEvent", | |
| "Fields" : fields | |
| }; | |
| //Create Data Extensions | |
| var UnsubDE = DataExtension.Add(UnsubEventDE); | |
| //Set columns to retrieve | |
| var cols = ["SendID","SubscriberKey","EventDate","EventType","TriggeredSendDefinitionObjectID","BatchID","Client.ID"]; | |
| //Initiate data extensions | |
| var logUnsubData = DataExtension.Init("05_UnsubEvent"); | |
| //Initiate WSProxy and set object properties | |
| var prox = new Script.Util.WSProxy(), | |
| objectType = "UnsubEvent", | |
| moreData = true, | |
| reqID = null, | |
| numItems = 0; | |
| //Retrieve data using pagination and insert data to UnsubEvent DE | |
| while(moreData) { | |
| moreData = false; | |
| var data = reqID == null ? | |
| prox.retrieve(objectType, cols, filter): | |
| 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++) { | |
| logUnsubData.Rows.Add({ | |
| SendID: data.Results[i].SendID, | |
| SubscriberKey: data.Results[i].SubscriberKey, | |
| EventDate: data.Results[i].EventDate, | |
| EventType: data.Results[i].EventType, | |
| TriggeredSendDefinitionObjectID: data.Results[i].TriggeredSendDefinitionObjectID, | |
| BatchID: data.Results[i].BatchID, | |
| ClientID: data.Results[i].Client.ID | |
| }); | |
| numItems++; | |
| } | |
| } | |
| } | |
| } | |
| Platform.Response.Write("<br>Inserted " + numItems + " records<br>") | |
| }catch(e){ | |
| Write(Stringify(e)); | |
| } | |
| </script> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment