web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Subscription Center - Java Script

(0) ShareShare
ReportReport
Posted on by 140

Hello Community,

does anyone has a java script example for subscription center?

When the contact clicks "do not email" all subscription lists should be deactivated!

Thank you!

Best Regards

Jennifer

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Jennifer,

    As per my understanding, you could try code below, run it at "afterFormLoad" event of marketing form. 

    1. Get id value of "Do not email" input field and subscription lists in HTML mode of marketing page.

    We can find that "Do not email" element block is named as "data-editorblocktype="Field-checkbox"" and subscription list element block is named as "data-editorblocktype="SubscriptionListBlock"" by system.

    6138.x11.JPG

    2. At change event of "Do not email", check whether the checked property of "Do not email"  equals to true,

    if yes, uncheck other checkbox fields.

    MsCrmMkt.MsCrmFormLoader.on('afterFormLoad', function () {
      document.getElementById("bddafd65-310b-4d51-91b4-d251a5002add").addEventListener('change', function () {
        if (this.checked === true) {
          document.getElementById("66021523-07dd-ea11-a813-000d3aa08990").checked = false;
          document.getElementById("6c80c140-dfe1-ea11-a813-000d3aa08990").checked = false;
        }
      })
    });

    If I checked the "Do not email", then all subscription lists will be unchecked.

    pastedimage1597817059768v1.png

    Regards,

    Clofly

  • Jenni221 Profile Picture
    140 on at

    Thank you very much!

    And where do i have to put this script? in the marketing form or in the standard marketing page?

    I use the standard subscription center?

    How do i proceed when we host it externally via iframe?

  • cloflyMao Profile Picture
    25,210 on at

    Hi Jennifer,

    We should put the script on marketing page.

    From my using experience, I always put it after end tag of body element.(And the script should be nested in script tag.)

    3223.JPG

    ---  How do I proceed when we host it externally via iframe?

    I am not so clear about what does "host it externally via iframe" mean.

    Could you share me more details about it?

    As per my understanding, do you mean the form is being hosted on an external website such as Wordpress?

    If so, as far as I know, some WP plugins might create an iframe element on page and custom elements would be put to the iframe.

    To handle such situation, we could:

    > If custom elements were actually put to iframe, then we need to paste form embedding script to web page directly without using plugin. 

    > If iframe is actually another web page, then we should put the script to that corresponding page.

    In a word, elements in iframe couldn't be accessed.(A more accurate statement is that we couldn't inject javascript into iframe.)

    Please kindly point out if I had misunderstood towards your question.

    Regards,

    Clofly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 109 Super User 2026 Season 2

#2
Syed Aqib Raza Profile Picture

Syed Aqib Raza 88

#3
ParthPatel249 Profile Picture

ParthPatel249 82

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans