I have a Script task in Automation Studio that sends a small JSON payload to a rest api. The payload consists of the business unit, the Automation job name, a status and timestamp. My account has around a dozen business units and I have many jobs to monitor. I'm looking for execution and/or account context variables I can use in my script so that I don't have to create this script over and over for every job. I'm looking for something similar to the below, but I can't find anything in the documentation that seems helpful here.

var dt = new Date();
var datestring = Format(dt,"yyyy-MM-dd HH:mm:ss");
var payload = {
     "businessunit": "%%memberid%%",
     "jobname": "%%job.name%%",
     "completedTime": datestring
  • Are you looking for an immediate send to this endpoint to alert when the job is done, or is it more of something that can be done in bulk over a schedule? Aug 24, 2020 at 18:38
  • The intent is that it would be immediate. I'm using this as a notification service that data is ready to be picked up and synced to another system. Doing that entirely time-based is prone to error if jobs fail or take longer than expected Aug 24, 2020 at 18:40
  • You don't have access to these variables within your SSJS script, but how about creating your script programatically where your code knows the name of the Automation being run? Basically, you'd use the APIs to retrieve all Automations and add your script as the last step in each Automation.
    – Macca
    Aug 25, 2020 at 2:49

1 Answer 1


Based on comments, this was not in reference to email sends, but instead to data exports/imports/etc. These would require unique scripts for each to send notification as Script Activities are processed out of context of the Automation so there is no shared context variables to pull in.

I am retaining my original answer based on email jobs for reference if anyone needs it.

Original Answer

There is not really a good solution for this - especially when done in real time. Best option I can think of for this is below:

Email Send Log to fill Script for Call

Have an insert inside each email to push the job specific info into a data extension.

if _messagecontext == "SEND" AND _IsTestSend == 0 THEN
  set @logged = Lookup(@logDE,"logged","Job",jobid,"MID",memberid)
  if EMPTY(@logged) or @logged == 0 then
    insertDE(@logDE,"Job",jobid,"MID",memberid,"status","complete","completedTime",NOW(1), "logged",1)

and then have a script activity that pulls this info in and shoots out the calls, and then note in the row that it was already run.

Example of DE format: (create in a shared folder so all BU can access/write)

Job  |  MID  |  Status   |  CompletedTime  |  Logged  |  Run
Num  |  Num  |  Text     |  Date           |  Boolean | Boolean

Where Job and MID are pkeys. And the rest are nullable. You can place defaults however you like, but I would recommend having Run default to false.

You then set up your script to make the call like so:

var rows = Platform.Function.LookupRows(logDE,'Run',false);

if(rows && rows.length > 0) {
  for(var i=0; i<rows.length; i++) {
     var job = rows[i].Job,
         mid = rows[i].MID,
         status = rows[i].status,
         completedTime = rows[i].completedTime;
     var payload = {};
     payload.businessunit = mid;
     payload.jobname = job;
     payload.status = status;
     payload.completedTime = completedTime;

     //your API call here sending the payload

     Platform.Function.UpdateData(logDE, ["Job","MID"], [job,mid],["Run"],[true]);

Then add this script activity at the end of each of your automations with emails. This will then send all the logged jobs that have not been sent already to your API call. Even with the 'run' flag, you can have some risk that a job will be sent across twice if the timing is right or other cross overs, but of all the options in 'real time' I think this is the lowest risk.

The other item that can be a risk is that every email you send will need to have that AMPscript I wrote at the top in it, or this entire process will fall over.

You may want to write a monitor automation to run at X interval to compare the jobs in the _Job Data View to the Jobs inside of your Log. The issue comes in that the Data View is specific to a BU, so you would need to run this checkup in every BU. I would say to do a query on an enterprise sendlog for unique JobIDs, but sounds like the volume of sent messages is significant and likely this would time out.

Finally, a note that this will not work right for any triggered/journey sends as they retain the same JobID until republished. That would have to be handled differently.

Alternative solution to Email Snippet
If you feel unsecure about the AMPscript log, you can get around this by adding an extra step in your automation with a query to replace it. This would look at the Job DV for any new jobs run in the past X time period and add it to the same DE that the log would.

SELECT j.JobID as Job,
  j.AccountID as MID,
  "complete" as status,
  j.DeliveredTime as completedTime,
  1 as Logged
FROM [_Job] j
WHERE DeliveredTime > DATEADD(hour, -1, GetDate())
AND TestEmailAddr = ''
AND category != 'Test Send Emails'
  SELECT TOP 1 e.JobID as Job, e.AccountID as MID
  FROM ENT.[logDE] e
  WHERE j.JobID = e.JobID AND j.AccountID = e.AccountID

This will then provide all jobs in the past hour (can adjust to whatever timeframe you want) that have been sent from that Account to the log de.

I have conditions to remove test sends from it to ensure only production sends are pushed. I also added a not exist to stop the query from trying to add in data that already exists in the Log DE.

The rest of your process would remain the same.

  • Now I feel like my terminology has led us both down the wrong path. When I say "Job", I'm talking about a scheduled Automation task. We have many of these that run, mostly either DataExtract tasks or Query+FTP tasks. These are the jobs I'm trying to get context about so I can say that they've completed and are ready to be extracted and synced to our data warehouse. If I have these scheduled for say 4am, I'd rather pick up the files when they're done, rather than guess they'll be done by 5am Aug 24, 2020 at 19:50
  • These would require unique scripts for each to send notification as Script Activities are processed out of context of the Automation so there is no shared context variables to pull in. Aug 24, 2020 at 21:55
  • Thank you very much for the quick response. It's not what I'd hoped for, but what I kind of expected. Aug 25, 2020 at 12:22

You must log in to answer this question.

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