0

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">
    Platform.Load("core","1");

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

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")
    }
</script>
  • Awesome!! Thank you so much. I will give that a shot. – Paulette Vallad Apr 10 '18 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> – Paulette Vallad Apr 19 '18 at 17:55
  • Try removing the comma from "var job, = Attribute.getValue('@jobID')" – Christopher Carswell Jul 5 '18 at 21:37

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.