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
    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. – Gortonington May 23 at 13:25
3

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))
  • 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 – Gortonington May 24 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 May 25 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. – Gortonington May 25 at 19:12
  • Thanks @Gortonington for your response. Can you provide a source/doc on this matter? I'm using a JS file for the WS and there is no Activity tab on these type of files to check if a call is counted as an activity. – Rachid Mamai May 27 at 8:24
  • 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 May 28 at 5:15

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.