Populate Dates Automatically From Marketing Forms in Customer Insights Journeys

Have you ever had the need for someone filling out one of your marketing forms to populate a date field? Or do you have a hidden field that you want to have todays date so you know when something happened? This post will show you how you can populate dates automatically in a date field on your real-time marketing form. It’s quick and simple but can help you out with extra historical information on a Lead or Contact record.

First, add your date field to your form. In my example I want to capture todays date when someone submits my Contact form, that way I know when they filled it out, or if they fill it out again I can sort and filter by this to find Contacts with the most recent submissions no matter when the Contact itself was created. I’ve made the field hidden.

Click to view in detail

Next, we need to open up the HTML and add in a short script below the closing style tag like you see here.

Click to view in detail

Feel free to copy the script below, just make sure you put the field name for your actual field in place of mvw_contactformdate or it won’t work. Then save your form and/or publish. Note that if the form was already live, you won’t see the changes right away. Tip for you, put #d365mkt-nocache at the end of the URL and refresh the page, that should make sure you are looking at the latest version of the form including your new script.

<script>
  document.addEventListener("d365mkt-afterformload", function () {
    const dateInput = document.querySelector('input[name="mvw_contactformdate"]');
    if (dateInput && !dateInput.value) {
      const today = new Date().toISOString().split("T")[0]; // Format: YYYY-MM-DD
      dateInput.value = today;
    }
  });
</script>

Once you submit the form, you should get your date field populated with todays date. Awesome! Easy right?

Click to view in detail

Want to populate a date in the future? You can do that with a few extra lines. Just use whatever number you need for your requirements instead of the +7 used in the example below.

    <script>
        document.addEventListener("d365mkt-afterformload", function () {
    const dateInput = document.querySelector('input[name="mvw_contactformdate"]');
    if (dateInput && !dateInput.value) {
      const today = new Date();
      // Add 7 days
    today.setDate(today.getDate() + 7); 
    const formattedDate = today.toISOString().split('T')[0]; 
      dateInput.value = formattedDate;
    }
  });
    </script>

Original Post http://meganvwalker.com/populate-dates-automatically-from-realtime-form/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
July 2025
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31    
« Jun   Aug »
Follow
Search
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...