CRMJettyBack to crmjetty.comContact us
Menu
Docs / Guides

CRMJetty Portal

Works with
Docs / Dynamics 365

Dynamics 365 Customer Portalv6.3.0

Docs / Salesforce

Salesforce Customer Portalv6.3.0

Docs / Business Central

Business Central Portal

Guides / Widgets

How to Add Custom JavaScript to the Portal

6 min readUpdated
Short answerOpen the page in Page Builder, the form in Form Builder or the list in Design → Lists, and open its code editor (Code Editor or JS Editor). Paste your JavaScript, select Save or Apply, then publish the page, form or list.

Custom JavaScript lets you change how a portal page, form or list looks or behaves beyond the settings in the builders, for example to highlight a section or adjust the layout to match your theme. Each page, form and list has its own code editor, and the code runs only where you add it.

Important: Custom JavaScript runs in your portal users’ browsers, inside their signed-in session. A mistake can break a page, hide data or stop forms from submitting. Test every script before it reaches portal users, and add only code you understand and trust.

Before you start

Where you can add JavaScript

Where Editor Save with Then
A page in Design → Page Builder Code Editor Save Publish the page.
A form in Design → Form Builder Code Editor Apply Publish the form.
A list in Design → Lists JS Editor Apply Publish the list.

Card templates under Settings → Portal Settings → Template Scripting → Card Template also have their own HTML, CSS and JavaScript sections.

Add JavaScript to a page

  1. Go to Design → Page Builder and open the page in edit mode.
  2. Select Code Editor.
  3. In the pop-up, paste or edit your JavaScript.
  4. Select Save.
  5. Publish the page.
Page Builder with the Code Editor pop-up open and sample JavaScript in the editor
Page Builder with the Code Editor pop-up open and sample JavaScript in the editor
Page Builder with the Code Editor pop-up open and sample JavaScript in the editor
Page Builder with the Code Editor pop-up open and sample JavaScript in the editor

Add JavaScript to a form

  1. Go to Design → Form Builder and open the form.
  2. Select Code Editor.
  3. In the pop-up, paste or edit your JavaScript.
  4. Select Apply.
  5. Publish the form.
Form Builder with the Code Editor pop-up open and the Apply button
Form Builder with the Code Editor pop-up open and the Apply button
Form Builder with the Code Editor pop-up open and the Apply button
Form Builder with the Code Editor pop-up open and the Apply button

Add JavaScript to a list

  1. Go to Design → Lists and open the list.
  2. Select JS Editor.
  3. In the pop-up, paste or edit your JavaScript.
  4. Select Apply.
  5. Publish the list.

Example: highlight a section

This example adds a CSS class to a page section whose HTML ID is welcome-banner, which the portal renders as custom-welcome-banner. It checks that the element exists first, so the script does nothing on pages without it.

(function () {
  function highlightWelcomeBanner() {
    var banner = document.getElementById('custom-welcome-banner');
    if (!banner) {
      return;
    }
    banner.classList.add('is-highlighted');
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', highlightWelcomeBanner);
  } else {
    highlightWelcomeBanner();
  }
})();

Then style the class in your custom CSS, for example .is-highlighted { border-left: 4px solid #0a66c2; }.

Follow the same pattern in your own scripts:

Test your script

Risks of custom scripts

Troubleshooting

The script has no effect: Check that you saved or applied the code and then published the page, form or list. Check the browser console for errors, and that the ID in your script includes the custom- prefix.

The page or form stopped working after you added code: Open the code editor, remove or fix the code, and publish again.

Did this solve it?No, contact support