1

I created a custom .aspx page in sharepoint designer that uses sp.js and I reference it like this:

<SharePoint:ScriptLink ID="ScriptLink1" Name="SP.js" runat="server" OnDemand="false" Localizable="false" LoadAfterUI="True"></SharePoint:ScriptLink>

I also import Mootols which resides in a folder:

<script type="text/javascript" src="js/FUIL/mootools-core.js"></script>

for some reason I can't get these two scripts to work together, I even have a custom .js file which I created myself with some methods that use the Sharepoint javascript client object model to retrieve and update my Sharepoint lists that works just fine, what could be happening?, IE is giving me this error: "Object does not support this property or method" in sp.js, sp.ui.dialog.js sp.runtime.js and sp.core.js, always in line 2 which I try to debug and comes as an unreadable mess.

I'm using IE8 (and can't use other browsers).

1 Answer 1

4

SP.js is included as a standard reference, so you should have no reason to include it in your page unless that has been explicitly removed from your master (in which case, lots of other stuff would probably be broken too).

That said, SP.js typically loads "on demand" to reduce the amount of bandwidth required to load the page initially. The correct usage of sp.js would be to call something like ExecuteOrDelayUntilScriptLoaded(myFunction, "sp.js"); where myFunction is the name of the JavaScript function containing what you want to do. This will tell SharePoint to wait until sp.js has loaded, then fire your function and execute your script.

If you're trying to manually load sp.js, SharePoint may be trying to load the file twice, which could be what's driving your errors (you can't have the same objects exist twice).

I have a blog post which demonstrates the practice of using this approach. It's not at all related to mootools, but it illustrates the structure to scripts that use sp.js.

6
  • I tried removing the reference and using this script now: ExecuteOrDelayUntilScriptLoaded(initspa(), "sp.js"); var context; function initspa(){ context = SP.ClientContext.get_current(); } apparently SP is "undefined" which I assume indicates sp.js isn't loaded, one thing, these pages are blank aspx pages created via sharepoint designer and stored in the pages publishing library, not "sitepages".
    – eddnav
    Commented Jul 13, 2012 at 15:23
  • 2
    As long as they're using the site's master page, the fact that they were created in SPD shouldn't matter. Note that your ExecuteOrDelayUntilScriptLoaded call should not have parenthesis in the function name. It should be ExecuteOrDelayUntilScriptLoaded(initspa, "sp.js")
    – webdes03
    Commented Jul 13, 2012 at 15:51
  • I would also add an alert("sp.js Loaded") to your initspa function for testing purposes... so you know if the function has fired or not.
    – webdes03
    Commented Jul 13, 2012 at 15:52
  • I tried adding the alert, and it's like ExecuteOrDelayUntilScriptLoaded isn't doing anything
    – eddnav
    Commented Jul 13, 2012 at 16:17
  • ExecuteOrDelayUntilScriptLoaded(createListItem, "sp.js"); function createListItem() { var context = SP.ClientContext.get_current(); var nomb=document.getElementById('firstname').value; var apell=document.getElementById('lastname').value; ...
    – eddnav
    Commented Jul 13, 2012 at 16:17

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.