Archive for September, 2014

Introduction

In Share Point we have If condition “If this user is member of this share point group”
We can use this condition to check any user belongs to particular group or not.

Cause:

Check user belongs to a SharePoint Group and Hide some controls in New/Edit Forms on SharePoint Custom List

g1

 

Solution:

The following Script which will help you in checking if the current logged in SharePoint user belongs to a SharePoint user group and based on it hide some controls in New/Edit  forms on Custom List.

Step 1: Navigate to your SharePoint 2013 site.

Step 2: From this page select Site Actions | Edit Page:

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”.

Step 3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link; click it. You can insert the HTML and/or JavaScript as in the following:

Script

<script src=”/sites/JS/jquery-1.4.2.min.js”></script>

<script type=”text/javascript”>

ExecuteOrDelayUntilScriptLoaded(disableControls, “sp.js”);

 

var clientContext = null;

var web = null;

var users ;

var oList;

var oListNew;

 

function disableControls()

{

clientContext = new SP.ClientContext();

var groupCollection = clientContext.get_web().get_siteGroups();

var group = groupCollection.getById(4);//the SharePoint usergroup

users = group.get_users();

clientContext.load(group);

clientContext.load(users);

currentUser = clientContext.get_web().get_currentUser();

clientContext.load(currentUser);

clientContext.executeQueryAsync(Function.createDelegate(this,

this.onQuerySucceeded), Function.createDelegate(this,

this.onQueryFailed));

RefreshCommandUI();

}

function onQuerySucceeded()

{

if(this.users.get_count() >0)

{

var UserExistInGroup = false;

for(var i=0; i < users.get_count(); i++)

{

 

if(users.itemAt(i).get_loginName() == this.currentUser.get_loginName())

{

UserExistInGroup = true;

break;

}

}

}

if (UserExistInGroup)

{

$(‘nobr:contains(“Approver”)’).closest(‘tr’).show();

}

else

{

$(‘nobr:contains(“Approver”)’).closest(‘tr’).hide();

}

}

function onQueryFailed(sender, args)

{

 

}

</script>

 

Final Result:

g2

Cause

This is a very common issue faced by 9 out of 10 SharePoint developers. The custom site Logo does not get reflected on the Web Part Page and hence the default logo is seen as shown in the screenshot:

Home Page

Picture13

NewTestPage (WebPartPage)

Picture14

Solution:

  1. Go to the Web part(NewTestPage) page
  2. Click on the “Page” tab at the top, Click on the “Title Bar Properties” at the right (in the ribbon)

    Picture15

  1. In the Image Link section on the right, paste in the image URL
    Picture16
  1. Click OK

Out Page: Web part Page:

Picture17

Introduction

When your list reaches 20 items or more, SharePoint decided to automatically replace this simple, clean, and elegant dropdown with some messy, sloppy, and difficult-to-use Complex Dropdown. This is meant to be an upgrade. The text box, with jQuery behind it, allows users to type the item that they’re looking for (which you can actually already do with a dropdown). However, in practice, it is prone to unexpected behavior:

Cause:

I have a requirement to cascade country andstate dropdown in SharePoint list. I have tried it using SPCascadeDropdowns and it’s not working more than 20 items in child dropdowns. This states my child dropdowns:

Picture9

Solution:

SimpleChild 
If set to true, the child dropdown will be converted to a “simple” dropdown – only if it is a “complex” dropdown on page load. Edit the page in the browser and add a Content Editor Web part, modify the web part and show the Source Editor to add the following code.:

Picture10

Picture11

Summary:

We made the cascading lookup to display more than 20 items successfully. The lookup column now works fine for more than 20 entries also.

Introduction

When you create a new web part page in SharePoint, its left navigation column becomes empty. Reason for this is that the left side navigation is defined in the Master Page using “PlaceHolderLeftNavBar” content place holder and templates for Web Part Pages shipped with SharePoint overrides this content place holder and deletes its content, thus displaying empty left navigation.

The solution for this is to change the page so it will not override the menu place holder, but inherit it from the Master Page. The place holders we are interested in are:

Solution- 

  1. There is this tag which needs to be deleted or commented (this one hides the left nav)
    Picture8
  2. Delete only this tag as this is what overrides the default nav coming from the master page.
    Picture6
  3. Leave this tag as it is, if this is deleted(as said in other posts) it leaves a blank row on top the left nav which is not what you would want.
    Picture7
  4. Save the file.

You will get a warning saying you are about to customize the page. Just go ahead and open that web part again. It should have that good left navigation.

Introduction

There are several ways to enable the developer dashboard in SharePoint 2010 and 2013. I always prefer the PowerShell method, but for the sake of completeness I will show several options here.

Notice that there are the following options for the Developer Dashboard:

  • On
    SharePoint 2010: The Developer Dashboard will always be rendered at the bottom of each page
    SharePoint 2013: The Developer Dashboard icon will always be displayed at the top right corner. It will not be appended to each page.
  • Off
    SharePoint 2010 & 2013: The Developer Dashboard will not be available
  • OnDemand
    SharePoint 2010: The Developer Dashboard will only be appended to a page after clicking on the icon in the ribbon
    SharePoint 2013: This mode is not available in 2013 since it reflects the behavior of On now

Enabling Developer Dashboard using PowerShell

$devdashboard =[Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;

$devdashboard.DisplayLevel = ‘OnDemand’;

$devdashboard.Update()

Write-Host (“Developer Dashboard Level: ” + $contentService.DeveloperDashboardSettings.DisplayLevel)

Program code

Enabling Developer Dashboard using Object Model

SPWebService service = SPWebService.ContentService;

service.DeveloperDashboardSettings.DisplayLevel=Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel.OnDemand;

service.Update();

Using STSADM

STSADM.exe -o setproperty -pn

developer-dashboard -pv OnDemand

Picture5

Conclusion

The Developer Dashboard can be disabled by setting the display level value to “Off”. As needed the display level can be set to “On”, “Off” or “OnDemand” in the above code snippets. This operation requires a farm administrator permission. Make sure you have farm admin access before enabling/disabling developer dashboard.

Introduction

In this article we discuss about to get the data from SharePoint List using Angular js and Rest api. I used REST API to talk to SharePoint and get the data from the list. I am not going to discuss much about the REST services as many folks has already done a great work on explaining about REST API service.

In this script we just saw, we have first created an Angular Controller with the name ‘spCustomerController’. We have also injected $scope and $http service. The $http service will fetch the list data from the specific columns of SharePoint list. $scope is a glue between Controller and a View. It acts as execution context for Expressions. Angular expressions are code snippets that are usually placed in bindings such as {{ expression }}.

Picture3

<h1>WelCome To Angular JS Sharepoint 2013 REST API !!</h1>

<divng-app=”SharePointAngApp”class=”row”>

<divng-controller=”spCustomerController”class=”span10″>

<tableclass=”table table-condensed table-hover”>

<tr>

<th>Title</th>

<th>Employee</th>

<th>Company</th>

</tr>

<trng-repeat=”customer in customers”>

<td>{{customer.Title}}</td>

<td>{{customer.Employee}}</td>

<td>{{customer.Company}}</td>

</tr>

</table>

</div>

</div>

In the view you can use the ng-repeat to iterate through the customers and display customer information.
Use the following procedure to create a sample.

Step 1: Navigate to your SharePoint 2013 site.

Step 2: From this page select Site Actions | Edit Page:

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”.

Step 3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link; click it. You can insert the HTML and/or JavaScript as in the following:

<style>

table, td, th {

border: 1pxsolidgreen;

}

th {

background-color: green;

color: white;

}

</style>

<scriptsrc=”https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js”></script&gt;

<scriptsrc=”http://code.jquery.com/ui/1.10.3/jquery-ui.min.js”></script&gt;

<script>

varmyAngApp = angular.module(‘SharePointAngApp’, []);

myAngApp.controller(‘spCustomerController’, function ($scope, $http) {

$http({

method: ‘GET’,

url: _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getByTitle(‘InfoList’)/items?$select=Title,Employee,Company”,

headers: { “Accept”: “application/json;odata=verbose” }

}).success(function (data, status, headers, config) {

$scope.customers = data.d.results;

}).error(function (data, status, headers, config) {

});

});

</script>

<h1> Angular JS SharePoint 2013 REST API !!</h1>

<divng-app=”SharePointAngApp”class=”row”>

<divng-controller=”spCustomerController”class=”span10″>

<tableclass=”table table-condensed table-hover”>

<tr>

<th>Title</th>

<th>Employee</th>

<th>Company</th>

</tr>

<trng-repeat=”customer in customers”>

<td>{{customer.Title}}</td>

<td>{{customer.Employee}}</td>

<td>{{customer.Company}}</td>

</tr>

</table>

</div>

</div>

 Finally result show below:

Picture4