Using Content snippets in javascript code on Entity Form Dynamics 365 Portals

In this post, I will be showing how to use a snippet in your javascript code. A powerApps Portal content snippet, using programming terms, is like a static global readonly variable that can be re-used anywhere within your code.

Create a content snippets in your PowerApps portals, make the type an HTML

In the above, I have create a content snippet called “Testing Snippets”, with a type of html and in the HTML value, I created an html div and anchor inside it, with its href pointing to a Contact-us page within portals.

The plan is to get this snippet and place it somewhere on a form. Using the below code :

$(document).ready(function(){
    var testinSniet = '{{snippets["Testing Snippets"]}}';
    $("#preferredcontactmethodcode_label").closest("div").before(testinSniet);
})

First, I retrieved the snippet using the name of the snippet, then I am getting the field (preferredcontactmethodcode) label on my account form and then placing the snippet after the div housing the preferredcontactmethodcode label. The result on the form is :

The div is placed right on top of the option set field, here I am telling the user, if they cannot find their option in the drop, Contact Us. When the ‘Contact Us’ is clicked, it opens a contact us page that is within portal on another tab.