Loading...

Thursday, October 31, 2013

SharePoint hosted app to enable Geolocation column

GeoLocation field is newly introduced column type in SharePoint 2013 .You will not see any field of type GeoLocation by  by default but It needs to be enabled with program. This is quite useful to
save the Geographic info in SharePoint List.

1)Create a SharePoint hosted app and open up the Start page , here before executing actual CSOM
   following  few lines , get the context of hostweb url , app Web url and loads the sp.js

<script type="text/javascript">
    var hostweburl;
 var appweburl;
var web;
var list;
var context;
    // Load the required SharePoint libraries.
    $(document).ready(function () {

        // Get the URI decoded URLs.
        hostweburl =
            decodeURIComponent(
                getQueryStringParameter("SPHostUrl")
        );
  
  appweburl =
            decodeURIComponent(
                getQueryStringParameter("SPAppWebUrl")
        );

        // The js files are in a URL in the form:
        // web_url/_layouts/15/resource_file
        var scriptbase = hostweburl + "/_layouts/15/";

        // Load the js files and continue to
        // the execOperation function.
        $.getScript(scriptbase + "SP.Runtime.js",
            function () {
                $.getScript(scriptbase + "SP.js", execOperation);
            }
        );
    });

2)Now with the help of CSOM ,create SP list with GeoLocation column added to it.

   // Function to execute basic operations.
    function execOperation() {

       
    //context = new SP.ClientContext(hostweburl);
    
 context = new SP.ClientContext(appweburl); 
 var appContextSite = new SP.AppContextSite(context, hostweburl);
   // this.web=context.get_web();
   this.web= appContextSite.get_web();   
     // Continue your program flow here.
  context.load(this.web);

var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title('CustomList');
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);

this.web.get_lists().add(listCreationInfo);
this.list = this.web.get_lists().getByTitle('CustomList');


var fldCollection = this.list.get_fields();
alert(fldCollection);

var geoField = context.castTo(
fldCollection.addFieldAsXml('<Field Type="Geolocation" DisplayName="GeoLocation" Name="GeoLocation" />',
true,
SP.AddFieldOptions.addToDefaultContentType),
SP.FieldGeolocation);
geoField.set_title("Geo Location");
geoField.update();
alert(geoField);

context.executeQueryAsync(
 genericSuccess,
 genericFail
);

}

function genericSuccess(sender, args) {
    alert('success');
}
    
function genericFail(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

    // Function to retrieve a query string value.
    // For production purposes you may want to use
    // a library to handle the query string.
    function getQueryStringParameter(paramToRetrieve) {
        var params =
            document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == paramToRetrieve)
                return singleParam[1];
        }
    }
</script>

3)Once this app is deployed successfully then you will see , List with name Custom List with  Geolocation locumn added to it in host site

Wednesday, September 18, 2013

Most Valuable SharePoint Community


Diagnosing Display Template : Classical Overview Of Configuring Item Templates for Search WebParts

 To know more about what is Control Display Template and Item Display Template , Read this post.
 To diagnose  query values in Display template (In search webparts) , Item_Diagnostic item template is  available OOB. 
 To Configure this Item Template in Search Results WebPart's Toolpane,proceed as follows

 1)Navigate to Master Page gallery-->Display Templates-->Content Webparts -->Item_Diagnostic.html
    and Edit the properties to to check Search Result Webpart as Target control Type
 

 2)Now Edit the Search Page and Search Result WebPart to Select this Item template


 3)I found that in office 365 site this gives following error,but this can be corrected.
    To do so,Download Item_Diagnostic.html,Open with editor 
    search for this code line
    var pictureMarkup = Srch.ContentBySearch.getPictureMarkup(pictureURL, 100, 100, ctx.CurrentItem,    "cbs- picture3LinesImg", line1, pictureId);
and replace it by 
 var pictureMarkup =' ';
 Now rename the file , and upload it in display templates folder and set Target Control Type as Search Result

Display Error: The display template had an error. You can correct it
 by fixing the template or by changing the display template used in either the 
Web Part properties or Result Types.


Cannot call method 'getPictureMarkup' of 
undefined (CoreRender: ~sitecollection/_catalogs/masterpage/Display Templates
/Content Web Parts/Item_Diagnostic.js)
But  this should work in SharePoint 2013
anyways this post is to provide classical overview of Configuring Item Template for Search WebParts
All Item Template for Refinement Search WebPart will be found in Filter folder Under Display Templates folder in MasterPage gallery

Monday, September 9, 2013

Composed Look In SharePoint 2013: Templatization Of Look and Feel

I think idea behind introducing  Composed Look  is ,
a)Preparing look and feel in form of template
b)Modifying the look and feel on the fly.
1)Take a look at following Image, which helps to change the background image of the Master Page, on the fly.

2)Once Composed look is created , Under Site settings -->Look and feel -->Change the Look -->Select recently created look and apply . Here is my site with change of background Image :)
 For more insight about .spcolor and .spfont files , see this post and this one

Thursday, September 5, 2013

Display Templates Bit By Bit

In SharePoint 2013 and Office 365, Content search Webpart and Search result Webpart respectively ,can be use to get the aggregated Contents based on conditions
Display Templates consists of 2 Templates
1) Control template
   a)  To show multiple groups Group template can be configured.
   b)  To show contents without groups Content Template can be configured directly
2)Item Template
Above contents are based on my understanding. If you want to modify this post please write into comments


Sunday, August 25, 2013

Security Trimming for Managed Navigation in SharePoint 2013

Managed Navigation is the new concept which is introduced in SP 2013. Manged terms can be used for Navigating to Pages but it has  few limitations .
one of the limitation is, there is no OOB way to apply security trimming. But Interestingly I found one :)
So , try as follows
1)In Pages Library, Edit Page property to update the Managed metadata column ( Wiki Category can be used  for the same purpose

2)Once the Page is tagged with specific Metadata , Open  up the  Hidden Taxonomy List and break the permission for this List (here you have to make sure that , the Page and Managed Term has same unique permissions)
So Navigate to siteurl/Lists/TaxonomyHiddenList/AllItems.aspx  and find  for the metadata term , for which the page was tagged for
3)Hit 'Shared With' --> 'Advanced Setting'  and provide unique permission to this term , so that this term will be visible to only particular group or user.


Friday, August 9, 2013

An OOB Webpart Customization Approach:Client Side Rendering Of List / WebParts using JSLink in SharePoint 2013

I read many articles regarding use of JSLink and this one for MDS enabled sites. But I would like to explain it at high level
Unlike in SharePoint 2010 OOB list customization/WebPart customization ,Now there is no need to override OOB css or writing javascript logic considering whole html rendered at runtime.
Using JSlink , OOB html can be replaced at elementary level as follows.


(function () {
    // Initialize the variable that stores the objects.
    var overrideCtx = {};
    overrideCtx.Templates = {};

   1) // Here customize list header by replacing header html
    
    overrideCtx.Templates.Header = "<B><#=ctx.ListTitle#></B>" +
        "<hr><ul id='unorderedlist'>";

   2) // Here this function will be called  n number of times where n is the numb         er of items in list or library

    overrideCtx.Templates.Item = customItem;

    3) // Here customize list footer by replacing footerhtml

    overrideCtx.Templates.Footer = "</ul>";

    
    // Register the template overrides.
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

// This function builds the output for the item template.
// It uses the context object to access announcement data.
function customItem(ctx) {

    // Build a listitem entry for every listitem in the list.
    var ret = "<li>" + ctx.CurrentItem.Title + "</li>";
    return ret;
}

This resolves problem about writing XSLT at listview/Dataview level.But in Content query webpart , still there is space for writing xslt but that's why Content search webpart is introduced . though it is available in on-premise version, try this link for it's replacement in office 365