1

I've created a Trigger Email (Email Studio> Interactions> Triggered Emails) whose external key is 2241.

This has 64 in completed count and 0 in queued and errored. I'm trying to get this 'completed' count (along with sub key, date/time email sent etc.,) using below SSJS.

But this does not seem to return completed count. Why is that? Any alternates / thoughts please?

Result from SSJS:

{
    "Status": "OK",
    "RequestID": "976ad729-ac1c-4fc2-bb93-49b5f778f2c8",
    "Results": [{
        "ObjectID": null,
        "CustomerKey": "2241",
        "Sent": 0,
        "NotSentDueToOptOut": 0,
        "NotSentDueToUndeliverable": 0,
        "NotSentDueToError": 0,
        "Bounces": 0,
        "OptOuts": 0,
        "InProcess": 0,
        "Queued": 0,
        "TriggeredSendDefinition": null,
        "Opens": 0,
        "Clicks": 0,
        "UniqueOpens": 0,
        "UniqueClicks": 0,
        "SurveyResponses": 0,
        "FTAFRequests": 0,
        "FTAFEmailsSent": 0,
        "FTAFOptIns": 0,
        "Conversions": 0,
        "UniqueConversions": 0,
        "Client": null,
        "PartnerKey": null,
        "PartnerProperties": null,
        "CreatedDate": "0001-01-01T00:00:00.000",
        "ModifiedDate": null,
        "ID": 0,
        "Owner": null,
        "CorrelationID": null,
        "ObjectState": null,
        "IsPlatformObject": false
    }],
    "HasMoreRows": false
}

SSJS

<script runat="server">
Platform.Load("core","1.1.5");  
try {
  var prox = new Script.Util.WSProxy();

  /* Set ClientID */
  if (mid) {
    prox.setClientId({ "ID": mid }); //Impersonates the BU
  }
  var customerKey = 2241;

  var cols = ["CustomerKey","Queued"];
  var filter = {
      Property: "CustomerKey",
      SimpleOperator: "Equals",
      Value: customerKey
  };
  var res = prox.retrieve("TriggeredSendSummary", cols, filter);

  var results = res
  Write(Stringify(res)) 

}
 catch (e) {
  Write("<br>" + Stringify(e))
}

</script>

1 Answer 1

2

The result from WSProxy will hold all retrievable informations but your request defines if the values are filled.

If you extend your cols array it will return the values for the property:

  var cols = ["CustomerKey","Queued","Sent"];

Here is a little helper function which allows you to get all available properties for an object:

function proxDescribe(prox) {
    this.cols = {};

    this.retrievableCols = function(objectType) {
        var c = this.cols[objectType];
        if (!c) {
            this.cols[objectType] = [];

            var req = prox.describe(objectType);
            var props = req.Results[0].Properties;
            if( props.length > 0 ) {
                for(var i=0; i<props.length; i++) {
                    if( props[i].IsRetrievable ) {
                        this.cols[objectType].push(props[i].Name);
                    }
                }
            }
            return this.cols[objectType];
        } else {
            return c;
        }
    };
}

var prox = new Script.Util.WSProxy();
var d = new proxDescribe(prox);

Write(Stringify(d.retrievableCols('TriggeredSendSummary')));

Output:

["ObjectID", "Client.ID", "Client.PartnerClientKey", "CustomerKey", "PartnerKey", "Sent", "NotSentDueToOptOut", "NotSentDueToUndeliverable", "Bounces", "Opens", "UniqueOpens", "Clicks", "UniqueClicks", "OptOuts", "SurveyResponses", "FTAFRequests", "FTAFEmailsSent", "FTAFOptIns", "Conversions", "UniqueConversions", "InProcess", "NotSentDueToError", "RowObjectID", "TriggeredSendDefinition.ObjectID", "Queued"]

You should only initiate proxDescribe (new proxDescribe) once so the cols array inside the function keeps it values throughout your script.

This is recommended in the documentation for describe due to the nature of their static values.

2
  • That retrieved the sent out. Thanks for that. Let me check the describe function. Apr 22, 2020 at 13:30
  • And that's for that helper function. Now I should be able to change cols and add all (or any number of required cols). Apr 22, 2020 at 13:32

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.