1

I am facing difficulties in showing a message. Below is the problem statement :

I have six textboxes on a cloud page which stores six digit coupon code(one digit each). I am trying to show a error message on the same cloud page based on a boolean field stored in data extension if the coupon is invalid. If it is invalid it will not redirected to next page and a message will be displayed.

I had successfully accessed the textboxes using client side javascript and concatenated the digits to form a coupon code and stored in a variable. But i am not able to access this variable in SSJS for further processing.

Please help.

Thanks

1
  • 3
    The issue is in the name. Client-side is run AFTER Server-side is complete. In order to 'pass a client-side variable to Server-side' you would need to do a POST or something similar to the page you are on and pass the value as a parameter. You would then need to have the SS code lookup this parameter and assign the value to a var. This would require the page to completely reload, as it needs to go back to the server in order to run server-side script. Commented May 23, 2019 at 13:25

1 Answer 1

4

Salesforce Marketing Cloud Server Side JavaScript is executed on the SFMC server. You can not interact with DOM.

What I would do is:

1: Create a WS on SFMC side to check if the coupon is valid

2: Call this WS using ajax. This way, there is no need to reload the page.

3: Based on the ajax response, show the error message

Landing Page code:

var serializedData = {
       textboxvalue_1: $("#textboxvalue_1").val(),
       textboxvalue_2: $("#textboxvalue_2").val(),
       textboxvalue_3: $("#textboxvalue_3").val(),
       textboxvalue_4: $("#textboxvalue_4").val(),
      }

    $.ajax({
        url: YOUR_WS_URL,
        type: "POST",
        data: serializedData,
        dataType: "text",
        async: true,
        success: function(response) {
            console.log(response);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            Materialize.toast(textStatus + ' - ' + errorThrown, 4000);
            console.log(textStatus + ' - ' + errorThrown);
        }
    });

WS code:

Get texboxes values using:

SET @texbox1 = RequestParameter("textboxvalue_1")

Do a lookup on your DE:

Return a result using:

OUTPUT(v(@results))
6
  • just as a note, each call to the WS will count as a 'view' on the cloudpage - meaning it will cost you money each time. Depending on volume, this can add up very quickly Commented May 24, 2019 at 16:02
  • @Gortonington : I am new to this so just to be sure about what i understood, i want to clear things. 1) When you say WS, are you referring to Web Service? 2) WS Code, as mentioned by Rachid, will be written in another cloud page and URL of this cloud page will be used in "url" of ajax request. Correct?
    – R Suri
    Commented May 25, 2019 at 19:05
  • Yes to all. All views/loads of a Cloudpage will cost money, so hosting the Web Service on a Cloudpage means that any time you run the Ajax call to it, it will cost money. So basically if your page is hosted on a Cloudpage - you would pay for the initial visit to the page, then pay for the ajax request - meaning that the one visit would cost a minimum of 2 'views'. But each time they check the coupon (Ajax call) it will cost another view. So if they decide to check the coupon multiple times, it adds to the cost each time. I would highly recommend hosting the WS on a 3rd party server. Commented May 25, 2019 at 19:12
  • 1
    Anything on a cloudpage is cost per view. Here is link to SFMC doc on super messages: google.com/url?sa=t&source=web&rct=j&url=https://… Commented May 27, 2019 at 11:29
  • 1
    Rather than using an actual Cloud Page, you could always host your WS as a JSON Code Resource in Cloud Pages to get around the Super Message cost.
    – Macca
    Commented May 28, 2019 at 5:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .