Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

How to add a cookie at the start of D365 Sales Onpremise v8.2

Posted on by 17
 
How can i set a cookie so that when D365 start, the cookie will be set
There is some OOB code that run to verify if this cookie exist and if the cookie exist it wont display a popup. If the cookie does not exist it will display a popup.
 
My eventual goal is to set this cookie so that the popup dont show up.
 
I cannot figure out a javascript/typescript file in d365 onpremise v8.2, where i can set this cookie so that its set right at the beginning when the application start

Mscrm.Utilities.setCookie("persistentTemplateTourCookie""HideTemplateTour", 60 * 24 * 365 * 100);
  • Suggested answer
    Saif Ali Sabri Profile Picture
    Saif Ali Sabri 338 on at
    How to add a cookie at the start of D365 Sales Onpremise v8.2

    My response was crafted with AI assistance, tailored to provide detailed and actionable guidance for your query.
    To add a cookie in Dynamics 365 Sales On-Premises v8.2 and prevent the popup from showing up as per your described scenario, you will need to inject the code in a location where it runs as soon as the application loads. 

    Step-by-Step Solution:

    1. Identify the Application Load Event
      In Dynamics 365, custom JavaScript can be injected into forms, web resources, or even through the SiteMap customizations. However, for application-wide changes like setting a cookie at the start, you need to use the onload event at the global level or a custom web resource that loads on all pages.

    2. Use a Global JavaScript Web Resource
      Create a JavaScript web resource that sets the cookie and ensure it’s loaded as part of your Dynamics 365 application.

      Steps:

      • Navigate to Settings > Customizations > Customize the System.
      • In the default solution, create a new JavaScript web resource. For example:
        • Name: setCookieOnLoad.js
        • Content:
          javascript
          // Function to set the cookie
          function setPersistentTemplateTourCookie() {
          Mscrm.Utilities.setCookie("persistentTemplateTourCookie", "HideTemplateTour", 60 * 24 * 365 * 100); // 100 years expiration
          }

          // Call the function immediately
          setPersistentTemplateTourCookie();
      • Save and publish the web resource.
    3. Ensure the Web Resource Runs Globally
      To run the web resource globally (i.e., across all forms or pages), you can add it to the Application Ribbon or the Form OnLoad Event of a globally used entity.

      Option A: Add it to a Globally Used Form

      • Open the form editor for a commonly used entity (like Account, Contact, or Dashboard).
      • Navigate to Form Properties.
      • Add your newly created setCookieOnLoad.js web resource to the form libraries.
      • Add a new OnLoad event handler:
        • Library: setCookieOnLoad.js
        • Function: setPersistentTemplateTourCookie
      • Check the Event is enabled checkbox.
      • Save and publish the changes.

      Option B: Inject Through the Application Ribbon

      • You can also inject the web resource globally by modifying the application ribbon XML or adding it to the Dashboard ribbon. However, this is more complex and usually unnecessary unless you require the cookie to be set outside of entity forms.
    4. Test the Implementation

      • Clear your browser cookies.
      • Open Dynamics 365 and verify the cookie is set as expected (persistentTemplateTourCookie with the value HideTemplateTour).
      • Confirm the popup is no longer displayed.

    Key Notes:

    • Custom JavaScript Placement: If you cannot find a file within Dynamics 365 to directly modify for this purpose, using a custom JavaScript web resource is the cleanest and most maintainable approach.
    • Mscrm.Utilities.setCookie: This function is part of the supported client-side API in Dynamics 365 v8.2. Ensure your syntax matches exactly, as it is case-sensitive.

    Troubleshooting:

    • If the popup still appears, check the browser’s developer tools to ensure the cookie is being set correctly.
      • Open developer tools (F12 in most browsers) and go to the Application tab.
      • Look under the Cookies section and confirm persistentTemplateTourCookie exists.
    • Ensure your JavaScript is published and added to a form or ribbon that runs globally.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans