[SalesForce] SSJS to call Content Block with AMPscript

Use case: Through automation studio, a script activity is use to call and reference a content area through the "ContentAreaByName" function. That content area contains AMPscript that performs specific functions. This idea come from and was detailed through this thread:

Using AMPscript with SSJS Activities

The process works great, but with classic content nearing retirement I would love to be replicate this with Content Builder. The issue is that whenever I build a Content Block instead of Content Area, and call either the "ContentBlockByName" or "ContentBlockById" functions the script errors every time. The AMPscript is validated and works as a Content Area, but will not work as a Content Block. The function I use is as below:

<script runat="server">
    Platform.Load("Core","1.1.3");
    var stream = ContentBlockById("[ContentBlockId]");
    Write(TreatAsContent(stream));     
</script>

Has anybody been able to achieve this?

Best Answer

I've accomplished this by using the following SSJS:

<script runat="server">
 var ampscriptCode = Platform.Function.ContentBlockByID("####");
</script>

The AMPscript was held in a regular HTML content block in Content Builder.

Platform Server-side JavaScript functions

Related Topic