4

I'm creating a custom content block by extending content builder as described here: https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.meta/mc-app-development/content-sdk.htm

I'm using the BlockSdk setContent method to populate the block after the user has selected the content from my extension. Part of the content that I'm passing in is server-side javascript to get some recipient data at email send time and make some requests to my server, but when the content is inserted the javascript block is being stripped out. What is the reason for the javascript being stripped out when calling setContent on the blockSDK? Do I need to use AMPscript for this use case?

This is a simplified example of what I'm trying to output:

<script runat="server">
  Platform.Load("core", "1");
  var firstName = Platform.Recipient.GetAttributeValue("First Name");
  Variable.SetValue("@FirstName", firstName);
</script>
Hello %%=v(@FirstName)=%%
1

For your specific use case, Ampscript would be the best method to apply personalisation using the custom block in Content Builder.

Or try using ContentAreaBy... using your SSJS declaration like:

<script runat="server">
    Platform.Load("Core","1.1.1");
    try {
        var stream = ContentAreaByName("my content area name");
        Write(TreatAsContent(stream));   
    } catch(e) {
        Write(Stringify(e));
    }
</script>

Cheers!

  • 1
    I did end up converting to AmpScript, but never came back to update my question. Thank you for your response! – Steven Low Jan 31 at 14:38

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.