2

Compa've added following script to JSLink property of a custom content type ( JSLink="~sitelayouts/ProjectFolder/script1.js" ):

window.alert("started");
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function() 
     {
      window.alert("executed");
     });

The problem is that "function" are not called. "started' message pops up, but not "executed".

I can see that sp.js get loaded after executing this script, but then nothing is happening. MDS disabled and I've tried both IE10 and Chrome, also in IE with Compatibility View enabled.

Do I miss something?

3
  • i am having the same issue. this will prevent me from migrating a 2010 site to a native 2013.
    – Ultra
    Sep 21, 2014 at 18:34
  • Hi, did you find any solution for this ?
    – Light
    Oct 4, 2016 at 5:57
  • @Light, added answer, hope it helps
    – Chetvergov
    Oct 7, 2016 at 14:40

2 Answers 2

1

Load first js files

<SharePoint:ScriptLink ID="ScriptLink21" Name="sp.runtime.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false" />
<SharePoint:ScriptLink ID="ScriptLink22" Name="sp.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false" />

Next call

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', ready);

function ready() {
    // some code here
}
0

The reason SP.SOD.executeFunc not fire is that corresponding module from js is not loaded because other module have to be loaded beforehand. Added reference to sp.runtime.js and sp.js and it works fine now.

==== Edit ====

As the original post is old enough and I don't have exact code from that case, here's a fresh one. The idea is the same.

Problem: following SP.SOD don't fire

SP.SOD.executeFunc('sp.js',
'SP.ClientContext',
'SP.DocumentSet',
'SP.DocumentManagement.js', 
function(){
...
});

Solution: adding neccessary prerequisites for SP.DocumentSet scope:

<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.DocumentManagement.js"></script>
<script type="text/javascript" src="/layouts/15/app.js"></script>

I've found this solution accidentially, would be grate if someone will eleborate more on this topic.

1
  • Hi, can you pls post code as well
    – Light
    Oct 10, 2016 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.