Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Overview

I have a CustomAction for a button on the ribbon that calls a command in a javascript file. The command fails in the inplview.debug.js file on the following lines (1745 - 1748) in the GetFocusInfo method:

while((focusBack.tagName !="A") && (focusBack.tagName !="BODY"))
{
    focusBack=focusBack.parentNode;
}

The problem is on the 2nd iteration, focusBack is null. I assume something about the event I'm passing is wonky. If I call the method directly from the javascipt console, it executes correctly.

I eventually gave up and used window.SP.UI.ModalDialog.showModalDialog({url:this.url});

But I'm still curious as to what's going on here. Maybe it's more appropriate as a general javascript question on stackoverflow.

Here is my custom action:

<CustomAction 
    Location="ScriptLink" 
    ScriptSrc="/_layouts/ASAP/CustomActions.js" 
    Sequence="1100" />    

<CustomAction
    Id="NewSupplementalDocument"
    Location="CommandUI.Ribbon"
    RegistrationType="ContentType"
    RegistrationId="0x0100C44D4F1333A44FC9893DC3CFC16541A0"
    Sequence="1200" >        
<CommandUIExtension>
  <CommandUIDefinitions>
    <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
      <Button   Id="Ribbon.ListItem.Actions.GISRowSupplemental"
         Alt="Supplemental Button"
         Sequence="5"
         Command="New_Supplemental"
         labelText="New Suppl"
         ToolTipTitle="Add a suplemental document to this GIS row."
         Image32by32="/_layouts/1033/images/formatmap32x32.png"
         Image32by32Top="-320"
         Image32by32Left="-64"
         TemplateAlias="o1" />
    </CommandUIDefinition>
  </CommandUIDefinitions>      
  <CommandUIHandlers>
    <CommandUIHandler Command="New_Supplemental"
        CommandAction="javascript:
            SP.SOD.executeOrDelayUntilScriptLoaded (LoadCoreAndGo,'sp.js');">
    </CommandUIHandler>
  </CommandUIHandlers>
</CommandUIExtension>

Here is my javascript file:

var inProgress = false;
var listName = 'GIS Row Supplemental Documents';
var list;
var url;

function LoadCoreAndGo() {
    window.SP.SOD.executeOrDelayUntilScriptLoade
      (GotoSupplementalNewFormUrl, 'Core.js');
}

function GotoSupplementalNewFormUrl() {
    if (!inProgress) {
        try {
            inProgress = true;
            var context = new SP.ClientContext.get_current();
            var web = context.get_web();
            this.list = web.get_lists().getByTitle(listName);
            context.load(this.list, 'Id');
            context.executeQueryAsync(Function.createDelegate(this,success),
                Function.createDelegate(this, fail));
        }
        catch(e) {
            alert(e);
            inProgress = false;
        }
    }
}

function success() {
    try {
        var id = String(this.list.get_id());
        this.url = '/_layouts/Upload.aspx?List={' + id.toUpperCase() + '}';
        window.NewItem2(event, this.url); <-- This is where it fails        
    }
    catch (e) {
        alert(e);
    }
    finally {
        inProgress = false;
    }
}

function fail(sender, args) {
    alert('Operation failed: ' + args.get_message());
    inProgress = false;
}

Any ideas on what the issue might be?

share|improve this question
    
Try to check if your global variable names do not conflict with OOB sharepoint variables. Sometimes it leads to magic javascript errors. –  Kai May 15 '12 at 10:59
add comment

1 Answer 1

up vote 1 down vote accepted

So you need just to display a modal dialog?

I'd recommend to use SP.UI.ModalDialog.showModalDialog directly rather than leveraging undocumented NewItem2 function. Example code:

SP.UI.ModalDialog.showModalDialog({
    url: '/_layouts/Upload.aspx?List={' + id.toUpperCase() + '}',
    title: 'Upload supplemental document'
});

P.S. Btw, I don't think you need to pre-load "Core.js" file. I suspect sp.js is already dependent from "Core.js" and so it will be loaded anyway.

share|improve this answer
    
Thanks for the tip about Core.js. I got a little carried away trying to figure out the issue ;) I mention at the end of the post that I am using SP.UI.ModalDialog. I'll move it to the beginning of the code to make it more noticeable. –  rboone May 23 '12 at 23:29
    
Is there a way to return the uploaded document's relative path? –  Pathachiever11 Aug 6 '12 at 19:06
    
Yes, you should use dialogReturnValueCallback for this purpose, and analyze return value. If you have any problems with that, please, post a separate question. –  Andrey Markeev Aug 7 '12 at 14:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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