Archive for November, 2015

Introduction

In this article you will learn how to apply REST Query Filter to Field with the SharePoint 2013 REST API.

SharePoint development using JavaScript for any time I require unique customization not possible using out of the box. One of the technical challenges you may come across in your travels is trying to perform a GET of list items and filtering where a column value. Seems pretty straightforward right?

Scenario

In old days working with SharePoint lists or library, many times we came across querying lists and applying filter on list items using CAML Query. We all know constructing long CAML query gets confusing and many lines of chunks as well.

But no worries REST is the life saver; with REST it’s very easy to filter lists and gives to flexibility using few lines or sometimes just on line of code.

In this post, I will be showing how you can use REST to filter or query on SharePoint lists and returns data as you want.

You’ll first start to craft your URI like the following:

https://<siteUrl>/_api/Web/Lists/GetByTitle(‘listname’)/items?$select*&$filter= Title eq ‘test’

  • $Select: Lets you select list columns you want to return
  • $filter: Condition based results.

Refer the following images and code for clear understanding.

divisions
Solution

1st Approach

Open the browser and add the following URL in the address bar:

https://hostssite/apps/TestAppsite/_api/Web/Lists/GetByTitle(‘Divisions&#8217;)/items?$select=*&$filter=Title eq ‘test1’

code

2nd Approach: Using JQuey

Step 1: Navigate to your SharePoint 2013 site.

Step 2: From this page select the 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“dialogue, go to the “Media and Content” category, select the “Script Editor” Web Part and click 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 code snippet:

  1. function Divsion ()
  2. {
  3.     var listName = “Divisions”;
  4.     var itemId=“”;
  5.     var Ownurl = _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getbytitle(‘ Divisions’)/items?$select=OwnerEmailID&$filter=Title eq ‘test1′”;
  6.     $.ajax({
  7.         url: Ownurl,
  8.         headers: { Accept: “application/json;odata=verbose” },
  9.         async:false,
  10.         success: function (data) {
  11.             var items = data.d.results;
  12.             if (items[0].OwnerEmailID != “”) {
  13.                 itemId = items[0].OwnerEmailID;
  14.             }
  15.         },eror: function (data) {
  16.         alert(“An error occurred. Please try again.”);
  17. }
  18.     });
  19. }

 

Advertisements

Introduction

In this article we will learn about Sharepoint2013 Only display User Login Name as Notification dialog box on UploadEx.aspx.

Scenarios

When we upload the existing document in the Document Library by unchecking the override existing file we get SharePoint OOTB exception saying ”A file with the same name already exists and it was last modified by i:o#.w|domain\username.”

In this case we have to trim the i:o#.w| which is SID or represents type of authentication used.

Refer below screenshot for clear understanding of requirement.

Figure 1: Requirement

Figure 2: After

Solution

Step 1: Open the sitecollection in browser. Go to SiteSetting -> MasterPage -> Check the selected Site Master Page and System Master Page.


Figure 3: Sitecollection

Step 2: Open the site in SharePoint Designer. Go to All Files -> _catalog -> masterpage.

Figure 4: Designer

Step 3: Open any one of the selected master page in step 1 in advance mode.

Step 4: Add below script before </head> tag. Check screenshot for reference.

  1. <SharePoint:ScriptLink ID=“ScriptLink_CustomUploadpage” name=“~sitecollection/Style Library/Scripts/CustomUploadScript.js” runat=“server” LoadAfterUI=“true” Localizable=“false”/>

Figure 5: Screenshot for reference

Step 5: Repeat step 4 for the other master page selected in step 1.

Step 6: Come to browser and open style library by going to site content -> style Library.

Step 7: Upload the CustomUploadScript.js file to script folder in style library.

Figure 6: Script