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">
Platform.Load("Core","1");
%%[
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", "me@me.com")
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">
</script>
Best Answer
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:
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.