Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
64 views
in SharePoint Server by 4 16 27

In SharePoint 2016 and SharePoint 2019, I can't publish a page that has script editor with JSOM code "SP.JS", I checked the console and found out this error "SP.UI.DialogOptions is not a constructor" in "sp.ribbon.js" but I am not using "SP.UI.Dialog" in my code!

Uncaught TypeError: SP.UI.DialogOptions is not a constructor
    at Function.SP.Ribbon.PageState.Handlers.showStateChangeDialog (sp.ribbon.js?rev=d4Y4E0ghdo65Uz4tti0FZw%3D%3D:2:198364)
    at SP.Ribbon.PageState.PageStateHandler.handleCommand (sp.ribbon.js?rev=d4Y4E0ghdo65Uz4tti0FZw%3D%3D:2:184202)
    at CUI.Page.CommandDispatcher.callCommandHandler (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:329463)
    at CUI.Page.CommandDispatcher.$BM_0 (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:328039)
    at CUI.Page.CommandDispatcher.executeCommand (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:327746)
    at SP.Ribbon.PageManager.executeRootCommand (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:337133)
    at SP.Ribbon.PageManager.executeRootCommand (sp.ribbon.js?rev=d4Y4E0ghdo65Uz4tti0FZw%3D%3D:2:125700)
    at CUI.Ribbon.$BL_1 (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:153278)
    at CUI.Ribbon.$2j_0 (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:153344)
    at CUI.Ribbon.$2j_0 (cui.js?rev=hkelvuz%2BDyOYNl9FmpxUvA%3D%3D:1:113481)

How to solve this error SP.UI.DialogOptions is not a constructor in SharePoint Server?


1 Answer

1 like 0 dislike
by 54 119 241
selected by
 
Best answer

JSOM is not working in SharePoint Server 2019 / 2016

Actually, I have many issues related to JSOM code in SharePoint Server, and the main issue was mainly related to the order of SharePoint JS files, so in case, you need to use JS code in your SharePoint Site to access SharePoint Objects using SPContext, you have to make sure that the SharePoint JS files were listed in the below order

<script type="text/javascript" src="_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.init.js"></script>
<script type="text/javascript" src="_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>

Then try to call your function using SP.SOD.executeFunc('sp.js', 'SP.ClientContext', yourfunctionname); or _spBodyOnLoadFunctionNames.push("yourfunctionname");

Example: Run JSOM script in SharePoint

<a href="#" onclick="RunJSOM();">Run JSOM in SharePoint</a>

So to get this JSOM code working in SharePoint, you have to do the following:

function RunJSOM(){
        
     SP.SOD.executeFunc("sp.js", 'SP.ClientContext', myFunction);
 }

function myFunction(){
     //add your code
}

For more details, Please check JSOM code is not Working in SharePoint 2016/2019

by 4 16 27
0 0
it's working, thank you
If you don’t ask, the answer is always NO!
...