Hot answers tagged

28 votes
Accepted

Trying to automate contact deletion with SSJS

Updated March 2020 to accomodate for v2 authorisation and tenant specific endpoints. Please see the example of how I use this for bulk deletion. You should use the REST API, using the ...
Lukas Lunow's user avatar
  • 21.1k
22 votes
Accepted

REST API Methods in AMPScript or SSJS

GREAT NEWS!!! Firstly I want to thank SFMC Global Support, for the first time since they were Salesforce they were actually EXTREMELY helpful and quick. (Shout out to Jeff Ross) We found out that ...
Gortonington's user avatar
  • 30.5k
16 votes
Accepted

Difference between AMPscript and SSJS

In everyday life, AMPScript is sufficient for most personalisation tasks, when it comes to emails and landing pages. SSJS offers a larger set of functions, which I mainly use for data integrations to ...
Lukas Lunow's user avatar
  • 21.1k
14 votes
Accepted

AMPscript / SSJS learning resources

It'd be great if the documentation was better. Unfortunately, there a very few resources outside of the SF ecosystem. IMO, you've found the best resource -- the marketing-cloud, ampscript and SSJS ...
Adam Spriggs's user avatar
  • 30.4k
14 votes

Using AMPscript with SSJS Activities

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 ...
David Devoy's user avatar
  • 2,615
14 votes

Making a REST API call from a Script Activity in Automation Studio

I've done a REST API call from a Script Activity. Here's an example: <script type="javascript" runat="server"> Platform.Load("core","1.1.5"); var DE = "Contacts_To_Delete"; var logDE = "...
Adam Spriggs's user avatar
  • 30.4k
13 votes

Using AMPscript in a Script Activity

Server-Side JavaScript gives us more flexibility. We can use Ampscript in Script Activities. I have used it. I am not claiming that this is the best solution, but we can do the same using some tricky ...
Kumar Akhil's user avatar
11 votes

Update Data Extension Field to NULL using WSProxy

There's a hidden feature of WSProxy to allow you to do this! If you were to write the raw SOAP call to set the value of a field in your DE record to NULL, you'd write it like this: <...
Sam Whitmore's user avatar
10 votes
Accepted

Trying to update fields in Data Extension with SSJS

Declaration of Server-Side JavaScript Block is incorrect and you have not included the SSJS libraries in your SSJS code. <script runat=server language="JavaScript" executioncontexttype="get"> ...
Palash Rai's user avatar
  • 1,824
9 votes
Accepted

Parse XML in Server Side Javascript

There are no SSJS functions to parse XML, but we have achieved this with SSJS by using regular expressions to parse the XML, which works really well. Here's a snippet to set you in the right direction:...
Eliot Harper's user avatar
  • 16.4k
9 votes
Accepted

Trying to InsertData or UpsertData using SSJS and I getting error message "Unable to retrieve security descriptor for this frame."

You're writing it like AMPScript, and SSJS UPSERT is different syntax. Which is why the Update works (correct syntax) but the UPSERT and INSERT don't. For example, below is a valid UPSERT: <...
Gortonington's user avatar
  • 30.5k
9 votes
Accepted

Delete Subscriber records in Salesforce Marketing Cloud

First, you need to create a sendable data extension, which at least should contain your subscriber key. This will be populated by querying Subscribers Data View, with your criteria defined in the SQL ...
Lukas Lunow's user avatar
  • 21.1k
8 votes
Accepted

SSJS to AMP script

First I want to start off that passing JSON or other array data back and forth between AMPscript and SSJS is impossible without first breaking it into parts and rebuilding. So if that is what you are ...
Gortonington's user avatar
  • 30.5k
8 votes
Accepted

Using AMPscript/SSJS how do you unsubscribe a subscriber from a child business unit?

You can likely handle this by using the ClientID (MID) option in your SOAP API calls. This allows you to impersonate into another BU inside your call. As a note, this is permission based, but as you ...
Gortonington's user avatar
  • 30.5k
8 votes
Accepted

SSJS Replace only replaces the first instance of needle

Figured it out, need to use the regex modifier g to replace all instead of the first instance. var stripped_guid = job_guid.replace(/-/g, '');
Deployment Failure's user avatar
8 votes
Accepted

ParseJSON using SSJS

You don't have any variable named msg. Try this: <script runat="server" language="javascript"> Platform.Load("Core","1"); var jsonresponse = Variable.GetValue("@response"); var json = Platform....
user3274635's user avatar
8 votes

Are there any external call out limits in Marketing Cloud?

To my knowledge, the following are the limitations: Callout Limits: Currently there is not much documented, but there is a 'limit' of 2000 SOAP calls per minute. The other consideration is that if ...
Gortonington's user avatar
  • 30.5k
7 votes
Accepted

Is it possible to retrieve the client IP address on a landing page?

Hmmm, that should work but it looks like it's not for some reason. I've tried a few different HTTP header fields and the HTTPRequestHeader() AMPscript function is not returning any of them. Never ...
Eliot Harper's user avatar
  • 16.4k
7 votes

Is it possible to retrieve the client IP address on a landing page?

I ran across the same problem today. In the end I found that, in SSJS, you can use Platform.Request.ClientIP which returns the client IP address as a string. Worked for me on a Landing Page. See ...
Jhu884's user avatar
  • 153
7 votes

Date manipulation Function SSJS

You can do date math like you would in regular JS. I typically use a simple function to format the date: <script type="text/javascript" runat="server"> Platform.Load("...
Adam Spriggs's user avatar
  • 30.4k
7 votes

Retrieve parameter passed with MicroSiteURL() with SSJS

actually as long as the parameter shows up in the URL (=GET parameter) this does work: <script runat="server"> // call page like: url.com/cloudpage?data=test Platform.Load("core&...
Jörn Berkefeld's user avatar
7 votes
Accepted

SSJS to delete files on enhanced FTP

You can open a support request to enable the 'Delete file from ET FTP or Safehouse' Extract Type in the Data Extract Activity, which will delete the file that matches the filename that you defined in ...
Eliot Harper's user avatar
  • 16.4k
7 votes
Accepted

Activate a Subscriber from Server Side Javascript

In your scenario, you'd use the update SSJS function to change the status of the subscriber. Here is an example: <script runat="server"> Platform.Load("core","1"); var subscriber = {"Status":...
Brad Sapkota - altus.digital's user avatar
7 votes
Accepted

SSJS Rows.Retrieve not returning any rows

I believe the issue relates to the "DataExtension.Init" part of your code. var stagingDE = DataExtension.Init('Third_Party_Email_Acquisition_Stagingv2'); This is because if you aren't retrieving any ...
Christopher Carswell's user avatar
7 votes
Accepted

Ampscript or SSJS method to copy data extension

EDIT So I figured out that the object we need is the DataExtensionField object - which is likely where the issue was coming in. See below for a working version that has successfully copied a DE: &...
Gortonington's user avatar
  • 30.5k
7 votes
Accepted

Get current location with AMPscript or SSJS

You can get the current page url in AMPscript by using RequestParameter('PageURL'). This gives you the url dynamically without you having to hardcode. Reference: Look at How to Fetch a html form's ...
Hemavantha Rajesh Varma Mudunu's user avatar
7 votes

Update Salesforce object with a Script Activity

You can't execute AMPscript directly from a Script Activity, since they're only for server-side JavaScript code. There are also no SSJS functions for updating SF objects. You can, however, force ...
Adam Spriggs's user avatar
  • 30.4k
7 votes
Accepted

Create Filter Definition via WSProxy

I gave up and did it with the API functions: var sfp1 = Platform.Function.CreateObject("SimpleFilterPart"); Platform.Function.SetObjectProperty(sfp1, "Property", "ID"); Platform.Function....
Adam Spriggs's user avatar
  • 30.4k
7 votes
Accepted

How can I read a cookie via SSJS?

Yes. You can read values via Platform.Request.GetCookieValue(cookieName); var myCookie = Platform.Request.GetCookieValue('myCookie'); The function returns a string and exposes the HTTP Cookie ...
Macca's user avatar
  • 8,196
7 votes

SSJS equivalent of DecryptSymmetric

Adam's answer will work for CloudPages, but not for a Script Activity in an Automation, as the following error will be returned when validating the Script Activity: AMPscript is not currently ...
Eliot Harper's user avatar
  • 16.4k

Only top scored, non community-wiki answers of a minimum length are eligible