Error when trying to run JS from a Flow (on success of form) - "Uncaught (in promise) TypeError: Cannot read property ‘apply’ of undefined"

Instead of using inline code like:

<script>
var stripe = Stripe('pk_test_MYKEY');
function runStripe() {
stripe.redirectToCheckout({
sessionId: dmx.parse('emailPack1form.data.stripe.data.id')
});
}
</script>

Copy the content between the <script> ... </script> tags (without the script tags) and paste it in a file named runstripe.js.

Then include the runstripe.js file on your page … before the closing body tag:

</div>
</main></div>
</div>
</div>
</main>

<script src="path/to/runstripe.js"></script>
<script src="bootstrap/4/js/popper.min.js"></script>
<script src="bootstrap/4/js/bootstrap.min.js"></script>
</body>

</html> 

Thank you @Teodor I will try this. Fingers crossed!

How will I execute this with the FLOW? Will it pick up the function from the include? Or I need to do something else?

No need to change the flow, it works the same.

1 Like

Thank you! Will try this out

I’ve updated the routing components, it should now evaluate the scripts.

dmxRouting.zip (1.9 KB)

Thanks @patrick - replaced the file and tried again, unfortunately no change - same error.

@patrick and @Teodor

So I’ve tried both suggestions above;

Replacing dmxRouting.js file with the new one provided.

  • I tried this with the previous approach with the script block in the content page. Same error.
  • I tried this with the suggested approach of creating a js file with the script block and then loading that as an include, following Teodor’s instructions. I tried placing the include in the content page AND the layout page as per Teo’s instructions. I also tried placing the include in the header. Same error whatever I try.

None of these have worked, please advise where to from here?

I find it very strange that it is not working from any position. Lets try a simple script block with just an alert like:

<script>alert('Script works')</script>

Try adding that script block in the places that you tried the one with stripe and let me know in which case it shows the alert and when not.

Hi @patrick - I placed this at the bottom of the content page - and then clicked on the link to take me to the page - the alert fired before redirected to the page, but when I close the alert it then redirects me.

I assume that’s the desired outcome? Or it fires too soon even?

I don’t think that’s the issue, the issue seems to be trying to run the JS file from the FLOW.

As long as it shows the alert it seems to run the script inside the content page, so that is good. But we still don’t know why it doesn’t work with the runStripe function.

Next we could try following script block:

<script>
function runStripe() {
  alert('Script works');
}
</script>

You the run the function using the flow and see if it shows the alert.

1 Like

@patrick it’s working!! It looks like your fix actually did work - as I was testing a million different ways to use FLOW - I left a typo in the correct runStripe function command. I’ve reverted it all back to the script block in the bottom, and with your fix this is now redirecting to Stripe. Thank you!!!

1 Like

This topic was automatically closed after 25 hours. New replies are no longer allowed.