Using JQuery to hide SharePoint 2013 List Item fields

Hiding unnecessary fields in DispForm.aspx/EditFOrm.aspx is something most of us implement within our SharePoint implementations. Here is a quick way to achieve that using JQuery.
Hiding any List Item fields
So you have many fields in your NewForm.aspx but you want to hide some like in the screenshot. I want to hide the fields I haven’t underlined.

I will click on Edit Page, and add a Script  Editor webpart on the page. From the below script, just change the number in which your fields appear on the page using a 0 index. So to hide the first field, enter 0, second field – enter 1 and so on.


$(document).ready( function() {
$("TABLE.ms-formtable>TBODY>TR:eq(3)").css('display', 'none');
$("TABLE.ms-formtable>TBODY>TR:eq(7)").css('display', 'none');
$("TABLE.ms-formtable>TBODY>TR:eq()").css('display', 'none');
$("TABLE.ms-formtable>TBODY>TR:eq(9)").css('display', 'none');
$("TABLE.ms-formtable>TBODY>TR:eq(10)").css('display', 'none');
})

Also you can do some formatting on your page using Jquery, for example I am making the font as BOLD for the list item entries.

$(".ms-formbody").css("font-weight","bold");

Also,
I want to hide the information in the screenshot, you can add this line as well.

$(".ms-descriptiontext").css("display","none");

Hope this helps someone looking for a similar scenario.

Advertisements

Programatically breaking inheritance and adding unique permission to List Items

Permission handling is something which makes SharePoint a favorite product within the industry. SharePoint has Permission levels in built for basic roles, however you can create your own permission levels and assign to Groups and then set those groups to access any site/library/list. Whenever a sub-site is created, it asks you if you want to inherit the permission from the parent site or want to create unique permissions. 

If you choose to inherit the permissions, it will copy the same set of permissions to the sub-site which will again be passed on to the lists/libraries you create. It may happen that for securing our content, we want to break this inheritance and want to assign unique permissions to restrict the users for certain actions and to make the content more secure. Inheritance can be broken manually using the Out of feature also and if you have a business logic in place, you can do it programmatically also. This blog post gives you code to break inheritance for items meeting certain criteria and assigning permissions to them explicitly. I am using ItemAdded() event receiver to do this. You can use it within workflow or any custom webpart as well.

SPGroup securityGroup = spWeb.SiteGroups["Security Group Name"]; 
SPRoleDefinition groupRole = spWeb.RoleDefinitions["Read"];

SPRoleAssignment roleAssign = new SPRoleAssignment(securityGroup);
roleAssign.RoleDefinitionBindings.Add(groupRole);

SPListItem listItem = spWeb.GetListItem("http://List Item URL");
listItem.BreakRoleInheritance(true);
listItem.RoleAssegnments.Add(roleAssignment);
listItem.Update();

SharePoint2010 : Manually sending items to Record Center

Once you have followed my previous blogs
you are ready to proceed and send the items you wish to the Record Center.
To manually, send the items to Record center, click on the dynamic dropdown for the item. Hover the mouse on Send To and select your record center that you have created. That’s it, SharePoint will do the rest as we have made our web application ready by creating Sent to connection and setting the content organizer rules.

Follow the screenshots for more clarity:


SharePoint2010 : Creating Send To connection

Follow the steps below once you have Created your Record Center. If you want to see how to Create Record Center, Click here.

Make a note of the Submission Web Service URL 
  • Navigate to your Record Center
  • Go to Site Settings
  • Click on Content Organizer Settings under Site Administration 


  • Select the Web URL and copy it to clipboard/notepad  (we will use it later)

Create Send To connection
  • Ensure that you have the required permissions to perform this procedure. To create a connection, you must be a member of the Farm Administrators group.
  • Go to SharePoint Central Administration, under General Application Settings, click Configure Send To Connections.

  •   In the Web Application field of the Configure Send To Connections page, select the Web application that hosts the site collections from which documents will be sent.

  • From the Send To Connections list, select New Connection.
  • In the Display name field, type a name for this connection. This is the name that users will see as one of the options to which to send a document.
  • In the Send to URL field, enter the URL which we copied in the initial steps. Click “Click here to test” if you want to confirm that you have entered a URL to a Content Organizer. This should bring you up the web service that transfers the document from source to destination.
  • To display this connection in the list that appears when a user clicks Send To, select Allow manual submission from the Send To menu.

From the Send To action list, select one of the following values:

  • Copy: Select this option to create a copy of the document and send the copy to the destination repository.
  • Move: Select this option to delete the document from its current location and move the document to the destination repository. Users will no longer be able to access the document from its original location.
  • Move and Leave a Link: Select this option to delete the document from its current location, move it to the destination repository, and leave a link at the current location indicating that the document has been moved. When a user clicks this link, a page will appear that displays the URL of the document and the document’s metadata.
  • In the Explanation dialog box, type the information to be added to the audit log when the user sends a document by using this connection. If you selected Move and Leave a Link in the previous step, the page that appears when the user clicks the link will also display the explanation.
  • Click Add Connection to create the connection.
  • Click OK.

Applying Retention Policy to SharePoint 2010

Records Management is one of the very important aspects of SharePoint 2010 along with document management. Retention can be set either on content types or on folders depending on business case. In this post, I will explain how to set retention on any SharePoint library.
To start with applying retention to your library items, let us create a content type and then we will apply the retention to the content type which will drive the documents throughout their life cycle.

Now that we have our content type ready, document is in the library with valid value in the metadata field, we can proceed to apply retention to the content type.

Step 1: Click on Library Settings > Information management policy settings (under Permissions and Management)

Step 2: You can see the Vouchers content type listed along with the by default Folder content type. Click on Vouchers content type.
Step 3: Check the Enable Retention check box and click on Add a retention stage
Step 4: To trigger off the retention, our custom column (Voucher Date) which we added while creating the content type will be listed here. Select Voucher Date from dropdown and put 2 years (for the sake of this post). This is where you will put in your business case and fill in the value you want.
Step 5: Once we selected the Voucher Date and entered the number of years, now it’s time to select the kind of action we would want to perform on the item. The Action dropdown will list the available actions to choose from.
Let us declare the item as record after 2 years (for sake of this post).

Select Declare Record and click on OK.

Now you will be directed to the previous page with your event described as below. If you want you can add another stage of retention based on your organisation policy. For example, you would want to delete the item after keeping it for another 5 years after you have declared as a record. So you can add another stage here. Also, you may want to send the record to Record Centre after certain period, you can add that here by adding a new stage.
And we are done. We have now successfully applied retention to our content type.
You can follow the similar way to apply retention to any folder; the process is exactly the same, so I am not mentioning it in my post.

The SharePoint job which works in background to make the retention work is Information management policy job and Expiration policy job. They can be scheduled as per your organization policy going into the Central Administration > Monitoring > Review job definitions (under Timer jobs).


Create Custom Content Type in SharePoint 2010

Content Management is an integral part of SharePoint 2010. It helps organize your documents, items and records in a way you have control over its life cycle. We can define what fields we want to use in content types and their data types. Also we can apply validations on the fields within a content type. This blog post describes creation of a custom content type within the site collection and using it within the document library.
Step 1:Create a content type “Vouchers” with some metadata columns.
Go to Site Settings > Site Content Types (under Galleries) > Create.

Step 2:Create two additional columns within the content type.

Step 3:Create a document library named “Payment Vouchers”.


Step 4:Enable use of Content types within the library.
Go to Library Settings > Advanced Settings (Under General Settings) and select Yes for Content Types.


Step 5:Add our custom content type to this library.
Click on Add from existing site content types and select our newly created content type “Vouchers” from the list and click Add. Also, I will remove the Documentcontent type available in this library by default to avoid any confusion.

Once we add the Vouchers content type and remove the Document content type, the New Item ribbon button in our library will look like below:


Step 6:Now we can upload some documents to this library.
Click on Upload Documents and browse your file to upload. Once the upload is done, you will be asked to fill in the metadata for our content type Vouchers.

If you note, we made Voucher Date as mandatory, which is marked as a red asterisk. After filling in proper metadata, click on Save to complete the upload. Content types can be very helpful when you have thousands of documents in the same library and you have many types of documents in it, so creating separate content types for them and saving them under their appropriate values with their respective metadata values can be very helpful within the organization. Also, content types are very useful when you have a similar kind of documents within your site in different libraries, so you can create a content type and re use it in all the libraries. Implementation of Retention schedules also is one key benefit of using own custom content types.