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

I'm stuck on somethin I feel should be pretty straightforward, but I can't quite figure out how to get around it. I can't share my exact code right now as it's inaccessible at the moment, but it is basically based off of what is given here: http://blogs.msdn.com/b/sharepointdeveloperdocs/archive/2010/01/28/how-to-create-a-web-part-with-a-contextual-tab.aspx.

So, I have a webpart. When I click on the heading for this webpart, my contextual tab and its contained buttons appear. Inside this tab I have a splitbutton whose menu is dynamically populated by results from a REST service. Each of these menu items is a FlyoutAnchor which in turn should have its menu items gotten dynamically from the same service. In order to do this, I need to be able to pass back the ID of the parent item(FlyoutAnchor) in order to get its accompanying children (items in the FlyoutAnchor's menu). I can't figure out a way to do that with my current setup based on the instructions at the link above, however, as there does not appear to be a way to pass back arguments to a PopulateQueryCommand. I was thinking I could even just tack on the ID name to the command name, however, due to the setup of the PageComponent, it does not seem like this is possible.

Does anybody have any idea of how I could possibly pass an argument to a SharePoint Ribbon Command (or achieve the same effect)? Any insight would be greatly appreciated, as I am relatively new to working with the SharePoint Ribbon.

share|improve this question
add comment

1 Answer

I ran into the same issue - the only workaround I could figure out is to walk the stack to determine the "sender".

            var curCaller = arguments.callee.caller,
                sourceControlId;

            // Walks the call stack to get the "root" function
            while (curCaller.caller){
                curCaller = curCaller.caller;
            }

             if (curCaller.arguments[0] && curCaller.arguments[0].currentTarget){
                sourceControlId = curCaller.arguments[0].currentTarget.id.toString();
             }
             else { // handle the case where the menu could not be dynamically populated on the first invocation, e.g., asynch call was made
                curCaller = arguments.callee.caller;
                while (curCaller){
                    // this will be true for the SP launchMenu function
                    if (curCaller.arguments[0] && curCaller.arguments[0].id && curCaller.arguments[0].id.toString().startsWith("MyCompany.MyApp.SP.Ribbon.WorkspaceTab.SendGroup.SendButton") > 0 ){
                        sourceControlId = curCaller.arguments[0].id;
                        break;
                    }
                    else {
                        curCaller = curCaller.caller;
                    }
                }
            }
share|improve this answer
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.