Skip to content

getGlobalCommands not found with custom Ribbon Page Component

26/11/2013

Hi there

In case you have a SP 2013 Publishing Page with a custom Ribbon Page Component ( which might work well in 2010 ) and you get a JS Error
“getGlobalCommands not found” or not defined , i have a quick solution for you .

There are many Examples out there containing a function like:

Pages.PageComponent.initialize = function () {
ULS_SP();
ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, Pages.PageComponent.initializePageComponent), ‘SP.Ribbon.js’);
}

And this is the problem. I woundered because getglobalcommands() is defined once the page is loaded !

So I checked and found out that this function is located on the Page itself (Remember Publishing Page !). So an

$(document).ready(function() {
Pages.PageComponent.initializePageComponent;
});

Instead of the ExecuteOrDelayUntilScriptLoaded or SP.SOD.executeFunc will solve your problem !

Have fun

sp2013beta

16/07/2012

here is th 15 wave download

http://www.microsoft.com/office/preview/en/try-more-products

Quicknav Expandable

29/02/2012

Just a little script you can put on your Master page to get the Quicknave Expandable.

(I still like the better approch with Js tree and a Management Webart, but this might be sufficient Winking smile )

<script type="text/javascript">
$(document).ready(function(){
      $("div.menu.vertical.menu-vertical ul:first-child").children().each(function(){
             var selected =  $(this).find("li .static.selected")  ;
                       $(this).click(function() {
             $(this).find("ul").toggle();
             changeICO(this);
            });
        $(this).children(":first").attr('style','display:inline-block');
        var ico  = document.createElement('img');
        $(ico).attr('style','margin-left: 4px;');
                if(selected.length  == 0){                  
                    $(ico).attr('src','/_layouts/images/TPMAX2.GIF');
                    $(this).prepend(ico); 
        $(this).find("ul").toggle();
                }else{
                    $(ico).attr('src','/_layouts/images/TPMIN2.GIF');
                    $(this).prepend(ico); 
                }
      })
})
function changeICO(caller){
    var src = $(caller).find(":first").attr('src');
    if(src == '/_layouts/images/TPMIN2.GIF'){
        $(caller).find(":first").attr('src','/_layouts/images/TPMAX2.GIF');
    }else{
        $(caller).find(":first").attr('src','/_layouts/images/TPMIN2.GIF');
    }
}
</script>

 

XSLT Listview First/Last Page

10/02/2012

Ok this is Quick & really Dirty:

Ever wondered why he XSL Listview in SharePoint has no First /Last Button ?

Cause it´s hard to do in a generic way!

it´s an extension of this

I found is only working for ID sorted views

Here is a Quick fix, which should way more generic but I leave his Up to you Winking smile

  1. Open Up  SPDesigner and open the View you like to advance
  2. Select the XSLT list view web part in SharePoint Designer, Select Design tab in the ribbon > Customize XSLT > Customize Entire View.
  3. Find following code.

    <tr>

    <td class=”ms-vb” id=”bottomPagingCell{$WPQ}”>

    <xsl:if test=”not($GroupingRender)”>

    <xsl:attribute name=”align”>center</xsl:attribute>

    </xsl:if>

    <table>

    <tr>

    <xsl:if test=”$dvt_firstrow &gt; 1″>

    <td>

  4. Add following line bellow above code.
  5. <a href=”[VIEWURL].aspx”>
                         <img src=”/_layouts/images/arrowendleft_light.gif” border=”0″ alt=”First Page” style=”margin: 3px 5px 3px 3px”  />
                    </a>

    Then go to first page function is done.

  6. Then find following code.
  7. </xsl:attribute>

    </xsl:otherwise>

    </xsl:choose>

    <img src=”/_layouts/{$LCID}/images/next.gif” border=”0″ alt=”{$Rows/@tb_nextpage}” />

    </a>

  8. ADD:
  9. <a >
    <xsl:attribute name=”href”>javascript:redir(“[ListNAME]“,”[VIEWGUID]“)</xsl:attribute>
    <img src=”/_layouts/images/arrowendright_light.gif” border=”0″ alt=”Letzte Seite” style=”margin: 3px 3px 3px 5px” />
    </a>

  10. So the problem is we need a view things or the redirect URL, which are
    -The last Row count to show
    -The ID of the Item before the last item to show Disappointed smile
    -The OrderBy Fieldref Name

    XSLT doesn’t´t have this , so lets get I by JS

    in PlaceHolderAdditionalPageHead add his Scripts:

<script type=”text/javascript” src=”jquery.SPServices-0.7.0.min.js”></script>
                   <script type=”text/javascript”>

                      function redir(listname,viewname){
                              //Listname and viewguid could be retrieved by SPService or XSL
                              $().SPServices({
                              operation: “GetView”,
                              listName: listname,
                              viewName: viewname,
                              async: false,
                              completefunc: function (xData, status) {
                                  var limit  =  $(xData.responseXML).find(“RowLimit”).text();
                                  var Viewurl = $(xData.responseXML).find(“View”).attr(“Url”);
                                  var OrderTitle = $(xData.responseXML).find(“Query”).find(“OrderBy”).find(“FieldRef”).attr(“Name”)
                                  // I Failed by getting his query string out of above view, maybe you can make it better ;-) 
                                  var query  = ‘<Query><OrderBy><FieldRef Name=”Jahre_x0020_der_x0020_Fertigstel” Ascending=”FALSE” /></OrderBy></Query>’;
                                  $().SPServices({
                                      operation: “GetListItems”,
                                      listName: listname,
                                      async: false,
                                      CAMLQuery: query,
                                      completefunc: function (xData, status) {
                                       var rows = $(xData.responseXML).find(“z\\:row”);
                                       var  totalcount  =  rows.length;
                                       var  pindex = totalcount -(totalcount % limit)- 1 ;
                                       var  pid = $(rows[pindex]).attr(“ows_ID”);
                                       var  currow = pindex+2;
                                       var url = SP.ClientContext.get_current().get_url() +”/” + Viewurl +”?Paged=TRUE”;
                                       if(OrderTitle != null){
                                               url+= “&p_”+OrderTitle+”=” ;
                                       }
                                       url += “&p_ID=” + pid + “&PageFirstRow=”+ currow ;
                                       window.location = url;
                                      }
                                  });
                              }
                          });

       
                      };
                    </script>

Resuming:

Could be way more generic (Ideas welcome)

XSLT and me are no going to be friends in his live anymore, sorry XSLT Sad smile

“T” key on my keyboard is sticky which drives me crazy

Have fun to get your Hands dirty

 

Lars

SharePoint 15 Rumor

01/02/2012

I was very excited hearing about the new SharePoint coming to beta this summer. At the same moment I couldn’t´t wait to get some information what’s  new in this release.

Then I found a chm from Microsoft itself, describing new Methods in the OM.

SharePoint 15 Technical Preview Managed Object Model Software Development Kit

My assumptions are:

  • HTML5 Lot of the classes are Targeting Client Integration / Json Serialization /Scripting /Dataconvertion ( An SPweb can hold Apps Winking smile)
  • OAuth2 Suppor for Sharepoint

Feel free o post more things you can read out of it

Update External List´s Projected Fields

03/01/2012

I had the Scenaio where Projected Fields coming from an external List has to be added after a while. Trying I yourself you will soon discover that these fields are left Blank until the item is opened and Updated once via UI. So I thought no problem , just iterate through Powershell and open save the item . Unfortunately it´s not that simple.

So I´m not the Guy of long txt Winking smile  so here is a Console App to help you out:

(Btw Pass through identity of the BDC doesn’t work for this)

Code Snippet
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using Microsoft.SharePoint;
  5. using System.Collections.Generic;
  6.  
  7.  
  8.  
  9. namespace SharePointConsoleApplication1
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             TextWriter tw = new StreamWriter("log.txt");
  17.  
  18.             using (SPSite site = new SPSite(@"yoursite"))
  19.             {
  20.                 using (SPWeb web = site.OpenWeb())
  21.                 {
  22.                     //get the List
  23.                     SPList spList = web.Lists["ListWithBDCField"];
  24.                     //Get the BDC Field from the list
  25.                     SPFieldCollection fieldCollection = spList.Fields;
  26.                     string intname = String.Empty;
  27.                     tw.WriteLine("List Open searching for BDC Field");
  28.                     foreach (SPField spField in fieldCollection)
  29.                     {
  30.                         if (spField.TypeAsString == "BusinessData")
  31.                         {
  32.                             intname = spField.Title;
  33.                             continue;
  34.                         }
  35.                     }
  36.                     tw.WriteLine("found " + intname);
  37.                     //Get the Projected Fields
  38.                     List<string> projected = new List<string>();
  39.                     foreach (SPField spField in fieldCollection)
  40.                     {
  41.                         if (spField.Title.Contains(intname + ":"))
  42.                         {
  43.                             projected.Add(spField.Title);
  44.                             tw.WriteLine("Projectfield – " + spField.Title);
  45.                         }
  46.                     }
  47.                     tw.WriteLine("Query Full list");
  48.                     //Get all Items
  49.                     SPQuery query = new SPQuery
  50.                     {
  51.                         QueryThrottleMode = SPQueryThrottleOption.Override,
  52.                         RowLimit = 20000
  53.                     };
  54.  
  55.                     SPListItemCollection allItems = spList.GetItems(query);
  56.  
  57.                     tw.WriteLine("All items contains :" + allItems.Count);
  58.                     int count = 0;
  59.                     foreach (SPListItem item in allItems)
  60.                     {
  61.                         try
  62.                         {
  63.                             //Extract the BDC Value Id and List
  64.                             tw.WriteLine("processing :" + count++);
  65.                             SPField myField = item.Fields[intname];
  66.                             XmlDocument xmlData = new XmlDocument();
  67.                             xmlData.LoadXml(myField.SchemaXml);
  68.                             String entityName = xmlData.FirstChild.Attributes["RelatedFieldWssStaticName"].Value;
  69.                             String listname = xmlData.FirstChild.Attributes["EntityName"].Value;
  70.  
  71.                             object o = item[entityName];
  72.                             if (null == o || String.IsNullOrEmpty(o.ToString()))
  73.                             {
  74.                                 tw.WriteLine("No BdcValue found , skip ");
  75.                                 continue;
  76.                             }
  77.  
  78.                             SPList list = web.Lists[listname];
  79.                             //Find the BDC Entity in the external List
  80.                             SPQuery q = new SPQuery();
  81.                             q.Query = "<Where><Eq><FieldRef Name='BdcIdentity' /><Value Type='Text'>" + o + "</Value></Eq></Where>";
  82.                             q.RowLimit = 10;
  83.                             SPListItemCollection col = list.GetItems(q);
  84.                             //Write the projected fields
  85.                             if (col.Count > 0)
  86.                             {
  87.                                 SPListItem litem = col[0];
  88.                                 foreach (string projextedfieldname in projected)
  89.                                 {
  90.                                     item[projextedfieldname] = litem[projextedfieldname.Split(new[] { ": " }, StringSplitOptions.None)[1]];
  91.                                 }
  92.                             }
  93.                             else
  94.                             {
  95.                                 tw.WriteLine("No BdcValue Lookup found , skip ");
  96.                                 continue;
  97.                             }
  98.  
  99.                             tw.WriteLine("Item Done");
  100.                             item.Update();
  101.                         }
  102.                         catch (Exception exception)
  103.                         {
  104.                             tw.WriteLine("—————————————————————-");
  105.                             tw.WriteLine("ERROR !");
  106.                             tw.WriteLine(exception.Message);
  107.                             tw.WriteLine(exception.StackTrace);
  108.                             tw.WriteLine("—————————————————————-");
  109.                         }
  110.                     }
  111.  
  112.                     tw.WriteLine("All Done ");
  113.                     tw.Close();
  114.  
  115.                 }
  116.             }
  117.         }
  118.  
  119.     }
  120. }

Search Listitem Projected Field

17/11/2011

It´s been a while since last post, but now one cute little Baby later I will start again to spread knowledge.

In case anybody comes around with the requirement to search for a Projected Field ( a Field that is shown in a View and Projected by a lookup item) , the answer is quite simple.

Just create a new Managed Property in the Settings of your Search Application in Central Admin and map the crawled Property to it (it´s called like your Projected column prefixed with “ows_”).

Add the Managed Property to the Fetched Properties in the settings of your Result Webpart and edit XSL to make a nice render.

 

continuing happily

Follow

Get every new post delivered to your Inbox.