Skip to main content

Notifications

Microsoft Dynamics CRM forum
Suggested answer

Using Custom Javascript On The Portal

Posted on by Microsoft Employee

Hi.

I have a requirement to hide certain things from the Sign In page.

Now as this is not defined as a web template I need to do this via javascript.

My understanding is that I should be able to create a new Web File record, attach my javascript file to this as a note and then each page on the site should contain this script file.

This is exactly what I did previously to get a custom css file available on all pages of the site.

However, this does not seem to work for javascript files. I have restarted the portal several times but the javascript is never present on any of the site pages.

Is there something else I need to do to make my javascript file take effect?

Categories:
  • Birgit RD Profile Picture
    Birgit RD 2 on at
    RE: Using Custom Javascript On The Portal

    Thank you Craig. This was the information I was looking for.

  • Suggested answer
    Craig P. Fleming Profile Picture
    Craig P. Fleming 950 on at
    RE: Using Custom Javascript On The Portal

    Ah yes now it makes sense, you will need to adjust the settings for your org to allow upload of files with the js extension. Navigate to Settings > Administration > System Settings and look at the Set blocked file extensions for attachments field. You should find that js is listed, simply remove it from the list (even if just temporarily to upload a single file).  You should then be able to upload your reusable js file.

    7610.2017_2D00_04_2D00_28_5F00_8_2D00_25_2D00_46.jpg

  • Birgit RD Profile Picture
    Birgit RD 2 on at
    RE: Using Custom Javascript On The Portal

    Craig,

    We are not able to upload a file with extension .js

    We tried to do it via de portal (New child). In that case, no error is displayed, but when inspecting the web file entry in CRM, no file in the notes section is added.

    Wen we try to add it directly in CRM, we get the error message "Invalid file type".

    As we don't succeed in uploading a javascript file, we have copied a couple of lines of javascript on every single web page. Not the most pleasant work, but at least we could work around the issue.

  • Craig P. Fleming Profile Picture
    Craig P. Fleming 950 on at
    RE: Using Custom Javascript On The Portal

    Unfortunately the signin page is a tricky one to deal with because of the nature of how that page is implemented. It's possible that the css could influence other aspects of the site unintended but that is not to say it's not possible. In js you can detect the url and control the logic a bit more carefully and make changes accordingly.  

  • Craig P. Fleming Profile Picture
    Craig P. Fleming 950 on at
    RE: Using Custom Javascript On The Portal

    pdiax1000, Just to be clear when you say "call it myscript.js but not upload a js file" if you mean you did not upload a file then this would be the expected result.  You need to upload the js file.

  • Suggested answer
    RamKumarb Profile Picture
    RamKumarb 826 on at
    RE: Using Custom Javascript On The Portal

    Hi jimbob,

               i don't think you can make changes in SIGN-IN page using custom javascript,  but you can hide certain things in signup page by modifying the CSS, like hiding the external login  button.  Removing the registration options for a new user etc.

    and yes you can add your custom javascript to a portal web-page and perform some operation .

  • Birgit RD Profile Picture
    Birgit RD 2 on at
    RE: Using Custom Javascript On The Portal

    Did anyone succeeded in adding a custom js file?

    I'm requested by Microsoft to do so for another issue, but facing same issue as pdiaz1000.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Using Custom Javascript On The Portal

    Hi, I tried this but didn't seem to work.. I might have miss something - so I did:

    create a web file as you normally would with CSS and maybe call it myscript.js but not upload a js file?

    Create a content snippet as above and put the script tag in when do you put your actual script ? when I tried this it said '404 not found .../myscript.js..'

    Any suggestion ?

  • Craig P. Fleming Profile Picture
    Craig P. Fleming 950 on at
    RE: Using Custom Javascript On The Portal

    Nithya, your documentation only applies to v7 self hosted portals. For v8 and beyond the web file technique is currently the only supported option.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Using Custom Javascript On The Portal

    Hi jimbob,

    The steps for adding the custom JavaScript to portal is explained in detail in the portal development guide below. Please go through the link.

    www.aayushsingh.in/.../adxstudio-portal-development-guide.html

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,377 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans