0

I have a script with moment js library running in a landing page and the purpose of the library is to check whether today falls in Daylight Saver.

If it does then the function sends a true statement and false if it doesn't.

In this context I want to capture the output of the function in an AMPscript variable so I can use it below to drive logics based on true or false results.

Here is what the landing page consists of:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<script type="text/javascript">
console.log(moment().format());
var CheckDLS = moment().isDST();
document.write(CheckDLS);
</script>

I have also tried doing HttpGet and HttpPost on the landing page which consists of the script.

Does anyone know how to achieve this? Also I am open to any other suggestions on getting the Daylight Savings status within cloudPages.

  • You can't mix server-side and client-side JavaScript. SSJS is evaluated before the page is loaded, client-side during (and after) page load. – Adam Spriggs Jun 2 at 14:18
1

You would need to use AJAX to post the Front End JS value to SSJS (either on page load, or on user activity).

Then you can use the Variable.SetValue to set it to a AMPscript variable.

| improve this answer | |
-1

If you just want to pass simple variable data back and forth, you will need to use the SSJS functions GetValue and SetValue.

E.g.

<script runat="server" language="javascript"> set var = 'Info'; Variable.SetValue("@Var","var"); </script> %%=v(@Var)=%%
| improve this answer | |
  • using SSJS won't allow me to use the JS libraries. If you look at my post above I have mentioned the use of moment JS library, and the issue is I need to capture that either with SSJS or AMPscript. Btw I have resolved the Daylight Saver issue so I am not looking for a solution. – Brad Sapkota Feb 19 '18 at 22:27

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.