I have tried using the below AMPscript block in an SSJS Activity, however it appears that Script activities only support SSJS and AMPscript cannot be included in Script Activities — please can someone clarify this?

<script runat="server">

SET @action = "start"
SET @id = CreateObject("ImportDefinition") 
SetObjectProperty(@id, "Name","Sonata Import") 
SetObjectProperty(@id, "AllowErrors", "true") 
SetObjectProperty(@id, "UpdateType", "Overwrite") 
SET @de = CreateObject("DataExtension") 
SetObjectProperty(@de, "CustomerKey", "InsertKeHere") 
SetObjectProperty(@id, "DestinationObject", @de) 
SetObjectProperty(@id, "FieldMappingType", "InferFromColumnHeadings") 
SetObjectProperty(@id, "FileSpec", "example-min.xml") 
SetObjectProperty(@id, "FileType", "Other") 
SetObjectProperty(@id, "Delimiter", "~") 
SET @ar = CreateObject("AsyncResponse") 
SetObjectProperty(@ar, "ResponseType", "email") 
SetObjectProperty(@ar, "ResponseAddress", "[email protected]")
SetObjectProperty(@id, "Notification", @ar) 
SET @ftl = CreateObject("FileTransferLocation") 
SetObjectProperty(@ftl, "CustomerKey", "Mercer Enhanced FTP") 
SetObjectProperty(@id, "RetrieveFileTransferLocation", @ftl) 
InvokePerform(@id, @action, @statusMessage)
<script runat="server">

3 Answers 3


I've spent some time trying to figure out why @David's script is errored even if the AMPScript code is validated on a CloudPage. Turns out it does work with Classic Content only (which already retired) and not with Content Builder.

So, to save you some time, try this code instead:

<script runat="server">  
var stream = Platform.Function.ContentBlockByID("YOUR_CONTENT_BLOCK_ID"); 

The AMPScript will be automatically be executed by the script activity.

This was tested with a Code Snippet block on Content Builder and works fine.


I've been able to successfully write script activities that reference AMPScript code. The trick is to place all your AMPSript code in a separate content area and call the content area from your script activity. The script activity window can only contain SSJS code.


<script runat="server">
    var stream = ContentAreaByName("some-content-area-name");


@KennethWagner asked how you write a script activity that will update a Salesforce object. I've verified the above script activity does work in this scenerio. It does require that the Salesforce Integration be configured for your account first.

To test this, I created a content area named 'some-content-area-name', which included the following code.

 set @ContactID = "003xxxxxxxxxxxxxx"
 set @result = UpdateSingleSalesforceObject('Contact',@ContactID,'Email','[email protected]')

I then created a automation to run the script activity above. Running the script activity in an automation allow me to verify the script completed successfully.

Lastly, I verify the update by looking up the contact record in Sale Cloud.

enter image description here

One final point of clarification, the Write statement surrounding the TreatAsContent() function is unnecessary. This is only helpful when testing the SSJS code from a landing page and coding the AMPScript block to actually output a value.

  • Using the query activity combined with AMPscript, could you copy an example of working ampscript code? I'm wondering how data is processed - if I need to use a FOR @i .... NEXT @i setup, or if it knows how to process individual records automatically? Commented Feb 7, 2017 at 9:15
  • @KennethWagner, do you mean script activity? Query activities are not compatible with AMPScript. Happy to help, but do you mind explaining your use-case a bit more? Commented Feb 7, 2017 at 15:18
  • Hi David ! Indeed, script activities. In a way i want to run some ampscript to update individual records in Salesforce. Just wondering how to structure the ampscript to make it work with your example above :-) Commented Feb 7, 2017 at 17:58
  • Hi Kenneth, I've updated the answer above with an example that uses AMPScript to update a Salesforce Object. Commented Feb 8, 2017 at 19:10
  • Hi David - Thanks for this ! :) however, the example illustrates my (potential) concern. I wouldn't be able to update a lot of different contacts.. or would i? Have you experimented with having X rows in a data extension, and then the lookup rows / for @i ... next @i ? I'm trying to figure out if I can use SSJS, ScriptActivity and AMPscript to update a lot of records in Salesforce, based on the content in a DE. New territory for me :-) Commented Feb 9, 2017 at 7:21

In a landing or microsite page, sure, you can mix them, but it appears that using the same method in a Script Activity doesn't work.

Here was my test -- add a Data Extension and then create a Subscriber:

<script runat="server">

    var deName = "000ASTest1";
    var deObj = {
        CustomerKey : deName,
        Name : deName,
        Fields : [
            { "Name" : "JobId", "FieldType" : "Number", "IsPrimaryKey" : true, "IsRequired" : true },

  SET @sub = CreateObject("Subscriber")
  SetObjectProperty(@sub,"SubscriberKey","[email protected]")
  SetObjectProperty(@sub,"EmailAddress","[email protected]")

  SET @subOpt = CreateObject("UpdateOptions")
  SET @saveOpt = CreateObject("SaveOption")

  /* update the subscriber object to true status */
  SET @stat = InvokeUpdate(@sub,@subMsg,@subErr,@subOpt)
<script runat="server">

It works for creating the DE, but if I add the AMPScript, here's what I get when I validate:

ScriptTest Error

You can do most AMPScript tasks with SSJS. Is there a specific one you're trying to accomplish in AMPScript that you can't do in SSJS?

  • Adam is correct, the activity will only recognize SSJS. Anything outside what is listed as acceptable by Exact Target will throw an error. (help.exacttarget.com/en-US/documentation/exacttarget/content/…). From this page you should be able to find the SSJS version of the AMPscript you listed above. Commented Nov 19, 2015 at 14:54
  • 2
    I suppose it's a possibility to use a landing page that contains a AMPScript/SSJS hybrid script and then use the GET() function it your Script Activity to execute it. Commented Nov 19, 2015 at 16:05
  • Thanks, trying to do InvokePerform() with SSJS but there's not a corresponding function for it. Will consider making a GET request. Commented Nov 19, 2015 at 18:07
  • 1
    There's an InvokePerform() SSJS function listed on this page: help.exacttarget.com/en/documentation/exacttarget/content/… Commented Nov 19, 2015 at 18:11
  • Thanks Adam, is there an alternative for TransformXML() in SSJS? Commented Nov 19, 2015 at 21:28

You must log in to answer this question.

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