Scenario: To make a new task field as unique in task list Sharepoint 2013

Leave a comment


Hi I have a scenario with Tasklists.

In the tasklist we observed that the title is allowing duplicate values so I thought of creating a new field with name “Task” which will have all features as Title and will not allow duplicate values.

1) First I created a field with name “Task” where I selected the option of Enforce Unique values and Required.
2)I went to server and run the below power shell script.Here in the code mention your site , list name and field.

Powershell script

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
#Get the web
$SourceWebURL = “http://xyz/sites/abc/”;
$Spweb = Get-SPWeb $SourceWebURL;
#update based on your list
$ListName=”TaskList1″;
$FieldName=”Task”;
$SPList = $Spweb.Lists[$ListName];
$field=$SPList.Fields[$FieldName];
$field.ListItemMenu = $true;
$field.ListItemMenuAllowed = 1;
$field.Update();
$SPList.Update();
write-host “Done”

Then just like by default Title now you can able to add all other functionality for new field Task.

tasklist.png

Advertisements

Expand Collapse feature for Left Managed Current Navigation in Share point 2013

Leave a comment


Hi all,

Sometime back I got a requirement from client that the left side navigation in Sharepoint can have expand collapse feature. There are 2 scenarios we can do. Implementation using jquery. Thanks to Christopher Pettigrew for his inspiration.

Don’t forget to refer jquery file.

  1. First Scenario:

First functionality will have navigation menu with list items and when ever a list item clicked the items will display like accordion and next list item clicked it will display the inner items but first list items will be in expanded form only.

 

$(function () {

$(“.ms-core-sideNavBox-removeLeftMargin li ul”).hide();

var Collapse = “/images/Minus_Icon.png”;

var Expand = “/images/Plus_Icon.png”;

 

//Find each top level UI and add reletive buttons & children numbers

$(‘.ms-core-sideNavBox-removeLeftMargin ul li’).find(‘ul’).each(function (index) {

var $this = $(this);

$this.parent().find(‘span:first .menu-item-text’).parent().parent().parent().prepend([‘<a class=\’min\’ style=\’float:right; margin-top:3px;\’><img src=\’/sites/XYZ/SiteAssets/images/Plus_Icon.png\’/></a>’].join(”));

});

 

$(“.min”).click(function () {

var img = $(this).children();

//Traverse the DOM to find the child UL node

var subList = $(this).siblings(‘ul’);

//Check the visibility of the item and set the image

var Visibility = subList.is(“:visible”) ? img.attr(‘src’, Expand) : img.attr(‘src’, Collapse);;

//Toggle the UL

subList.slideToggle();

});

});

2. Second scenario is:

If one list item i selected it will expand and the other list nodes must collapse.

$(function () {

$(“.ms-core-sideNavBox-removeLeftMargin li ul”).hide();
var Collapse = “/sites/xyz/SiteAssets/images/Minus_Icon_new.png”;
var Expand = “/sites/xyz/SiteAssets/images/Plus_Icon.png”;

//Find each top level UI and add reletive buttons & children numbers
$(‘.ms-core-sideNavBox-removeLeftMargin ul li’).find(‘ul’).each(function (index) {
var $this = $(this);
$this.parent().find(‘span:first .menu-item-text’).parent().parent().parent().prepend([‘<a class=\’min\’ style=\’float:left; margin-top:3px;\’><img src=\’/sites/xyz/SiteAssets/images/Plus_Icon.png\’/></a>’].join(”));
});

$(“.min”).click(function () {
var img = $(this).children();
//Traverse the DOM to find the child UL node
var subList = $(this).siblings(‘ul’);
//Check the visibility of the item and set the image
var Visibility = subList.is(“:visible”) ? img.attr(‘src’, Expand) : img.attr(‘src’, Collapse);;
//Toggle the UL
//subList.slideToggle();

$(“#zz15_RootAspMenu > li.static.father”).each(function() {
//you can find the menu id with chrome developer tool bar Inspect element on right //click and also you can see css will be different for list which is selected
// keep an alert(“hai”); to check whether your code entering below are not

var img = $(‘#zz15_RootAspMenu > li.static.father.selected > a > img’);
img.attr(‘src’, Expand);

});

});

/*set dynamic css logic*/
if ($(‘#sideNavBox .menu-item.selected’).length) {
//propagates the selected class, up the three.
$(‘li.static’).removeClass(‘selected’);
$(‘#sideNavBox .menu-item.selected’).parents(‘li.static’).addClass(‘selected’);

//collapses top siblings of selected branch
$(‘#sideNavBox .menu-item.selected’).parents(‘li.static’).last().siblings()
.find(‘> ul’).hide();
}
else $(‘#sideNavBox .root.static > li.static > ul’).hide();

/*set accordion effect*/
$(‘#sideNavBox .root.static > li.static’).each(function () {
if ($(this).find(‘ul’).length) {
$(this).addClass(‘father’).click(function () {
if ($(this).children(‘ul’).css(‘display’) != ‘none’) {
$(this).removeClass(‘selected’).children(‘ul’).slideUp();
}
else {
/*collapse-siblings*/
$(this).siblings().removeClass(‘selected’).children(‘ul’).slideUp();

/*expand*/
$(this).addClass(‘selected’).children(‘ul’).slideDown();
}

/*added: stop event propagation to link nodes*/
$(‘a.static’).click(function (event) {
event.stopPropagation();
});

/*added*/
return false;
});
}
});
});

expandcollapse

Fig shows expand collapse navigation

Please let me know your comments on this feature.

Client Side Rendering with JavaScript Templates in SharePoint 2013

Leave a comment


Share Your Point

Introduction

In SharePoint 2010 we used XSLT to customize the look of lists and forms. Client Side Rendering (CSR) in SharePoint 2013 is the next step in easy customization and changing the look of SharePoint. CSR is based on JavaScript (and HTML), so its flexibility allows using it in sandbox solutions and SharePoint Online where there is no place to use code-behind.

Parts of SharePoint lists that can be customized this way are:

  • List view
  • Forms – Display, New, Edit Form
  • Fields

View original post 357 more words

Control ‘GridView’ of type ‘GridView’ must be placed inside a form tag with runat=server.

Leave a comment


Please add below functions in code-behind cs file.

  public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}

public override bool EnableEventValidation
{
get { return false; }
set { /*Do nothing*/ }
}

Unable to see more than 100 Items from SharePoint list using Rest API

Leave a comment


In your custom list which is having more than 500 records. When you query with REST API it returns only 100 records.

Eg: http://<domain>/<site url>/_api/web/lists/GetByTitle(‘ListName’)/items

Solution:
To override that you need to append $top=3000 or $top=5000

Eg: http://<domain>/<site url>/_api/web/lists/GetByTitle(‘ListName’)/items?$select=AuthorId&$top=3000

Here authorId is CreatedBy Column.

Feel free to email me at bharath.chennu@onetidbit.com

 

 

How to identify sharepoint 2013 controls with javascript in a sharepoint newform.aspx and clear them

Leave a comment


Textbox with ID
Choice field with ID
DateTime with ID

but differs for Metadata field and Enhanced rich textbox

Metadata field will vary since its an array
===========================================

var myMetadataField = jQuery(‘div[Title=”Title of the field”]’).find(‘div [role=”textbox”]’);
myMetadataField.text(“”);

Enhanced Rich textbox
======================

var RichTTB=jQuery(‘div[id=”Rich_x0020_description_d7e728f9-1cc7-497a-8c6b- e7ec68ee9f97_$TextField_topDiv”]’).find(‘div[role=”textbox”]’);
RichTTB.text(“”);

People picker field
====================

var spclientPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[“_x0066_md4_62a2c22c-557e-4650-9454-cb293b0f44aa_$ClientPeoplePicker”];
if (spclientPeoplePicker) {
var ResolvedUsers = jQuery(document.getElementById(spclientPeoplePicker.ResolvedListElementId)).find(“span[class=’sp-peoplepicker-userSpan’]”);
jQuery(ResolvedUsers).each(function (index) {
spclientPeoplePicker.DeleteProcessedUser(this);

});
}

Get Users and update new user in People field of a particular List Item in Sharepoint 2013

Leave a comment


1) Use REST API url to get the users in people field
2) Write a function where we use ajax to get the data and declare an array and push the existing data along with user you want to add and at last update the listitem column People field.

You can write the code in a button click of a javascript.

Button
======

<input id=”btnUTSubmit” type=”submit” value=”submit” onclick=”insertToList();” style=”text-align: center;width: 100px;margin: 0 auto;display: block;”>

Function
========
Name of the function is: insertToList() and name of list is DOCS and columnname is SchoolUsers

function insertToList() {
var clientContext=SP.ClientContext.get_current();
//Let’s say here item id will be there in URL. We will get it by getting Querystring

// <siteurl>?pdfID=2
JSRequest.EnsureSetup();
itemId=JSRequest.QueryString[“pdfID”];
//REST URL
var urlForAllItems =”/_api/web/lists/getbytitle(‘DOCS’)/items(“+itemId+”)?$select=SchoolUsers/Title&$expand=SchoolUsers/Id”;

//function to get items

getItems(urlForAllItems);
}

Function to get Users and Update
=================================

function getItems(urlForAllItems))
{

$.ajax({

url: “https://abc.hyt/abc&#8221; + url,

type: “GET”,

headers: {

“accept”: “application/json;odata=verbose”,

},

success: function (data) {

var clientContext=SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle(‘DOCS’);
var itemId = getQuerystring(“pdfID”);
var itemToUpdate = oList.getItemById(itemId);
var users =[];

for(var i = 0; i < data.d.SchoolUsers.results.length;i++)
{

users.push(SP.FieldUserValue.fromUser(data.d.SchoolUsers.results[i].Title));

}

users.push(SP.FieldUserValue.fromUser(_sgContext.currentUser.Name));
itemToUpdate.set_item(“SchoolUsers”, users);
itemToUpdate.update();
clientContext.load(itemToUpdate);
clientContext.executeQueryAsync( );

alert(“Thanks for Update the field with new user”);

},

error: function (error) {

alert(JSON.stringify(error));

}

});
}

Older Entries

%d bloggers like this: