SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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"))

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:

    Sequence="1100" />    

    Sequence="1200" >        
    <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
      <Button   Id="Ribbon.ListItem.Actions.GISRowSupplemental"
         Alt="Supplemental Button"
         labelText="New Suppl"
         ToolTipTitle="Add a suplemental document to this GIS row."
         TemplateAlias="o1" />
    <CommandUIHandler Command="New_Supplemental"
            SP.SOD.executeOrDelayUntilScriptLoaded (LoadCoreAndGo,'sp.js');">

Here is my javascript file:

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

function LoadCoreAndGo() {
      (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');
                Function.createDelegate(this, fail));
        catch(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) {
    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
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:

    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? – harsimranb 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

Your Answer


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.