I am building a custom preference center in SFMC with SSJS that will pass the subscriber context into the landing page via the microSiteUrl() from an email. I am building and testing JUST the landing page portion. In my code I am using the Platform.Variable.GetAttributeValue('xxxxxxxxxx) to get the Subscriber Key, JobID and BatchID. I need these to log an unsub event.

When I go to publish (or even preview) the page I get an error. If I comment out the code, everything is fine. I know that technically the subscriber context isn't there because I'm not accessing the landing page via an email with microSiteUrl(). How can I get those 3 values (subscriberID, JobID and BatchID) and still publish the page?

This is my code:

<script runat="server">

    /*subscriber context */
    var subscriberKey = Platform.Variable.GetAttributeValue('_subcriberkey');
    var batchid = Platform.Variable.GetAttributeValue('BatchID'); 
    var jobid = Platform.Variable.GetAttributeValue('JobID');`

2 Answers 2


I usually set those variables in AMPscript, which still allows me to save the page even though there aren't any values.

SET @subscriberKey = _subscriberkey
SET @emailAddress = emailaddr 
SET @jobID = jobid 
SET @listID = listid 
SET @batchID = _JobSubscriberBatchID 

Then simple refer to them in SSJS using the following:

<script runat="server">
    Platform.Load("core", "1.1.1")
    var emailFields = {
        //NOTE: Retrieving AMPscript variables into SSJS if coming from email.
        subKey: Variable.GetValue("@subscriberKey"),
        emailAddress: Variable.GetValue("@emailAddress"),
        jobID: Variable.GetValue("@jobID"),
        listID: Variable.GetValue("@listID"),
        batchID: Variable.GetValue("@batchID")
  • Awesome!! Thank you so much. I will give that a shot. Apr 10, 2018 at 21:20
  • I finally got a chance to implement and the landing page will still NOT publish. This is the code. Am I missing something? <!-- AMPScipt to retrieve subscriber context--> %%[ SET @subscriberKey = _subscriberkey SET @jobID = jobid SET @batchID = _JobSubscriberBatchID ]%% <script runat="server"> Platform.Load("core","1"); /*retrieve values set in AMPscript */ var subKey = Variable.GetValue("@subscriberKey"); var batch = Variable.GetValue("@batchID"); var job, = Attribute.getValue('@jobID'); </script> Apr 19, 2018 at 17:55
  • Try removing the comma from "var job, = Attribute.getValue('@jobID')" Jul 5, 2018 at 21:37

Use from either of the two options below to retrieve the _subscriberKey :

Core Function:

var SubscriberKey = Attribute.GetValue("_subscriberKey");

Platform Function:

var SubscriberKey = Platform.Recipient.GetAttributeValue("_subscriberKey");

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.