Posts

Enable empty SP search textbox does not update results

Hi Guys, This post is about enabling empty search queries. By default, when user press 'Enter' on an empty Search Box, nothing happens.  A very simple question might be asked that why would anyone search for empty string any way?  True, no one actually needs it desperately but while going in flow this case could cause user bed experiences because users are likely to start with the refiners. Problem: Consider this flow: Navigate to SharePoint Search page Search with any keyword like "Test" If search results are not relevant, I just removed Test keyword from the textbox and hit search button. Nothing actually happens here. It suppose to clear all existing results. Without the ability to search for the empty string (or a "clear" button), the only way to do same would be to reload the page. Solution:  The Search Box webpart supports empty string search. Yes, its true, it's just disabled by default.  This feature is controlled by a property,  A...

Get user information SharePoint using REST Api

Hi, While working on a requirement, I encountered a scenario where I need to show welcome pop up to the first time users. First time user, SharePoint does not provide any api or any solution which gives information about users who logged on first time on your web site. I have documented the whole solution on some other post( Add welcome pop up for first time users of your site using AngularJs Material ) But this post I only want to scope it to retrieve information of logged on user. Information mean current user's accountId, First name, Last name, Email and other required details. I am only talking about client side code here i.e. using REST api or SP default APIs. Below are the various ways to get the property of current user who is logged on to SP site. There are many ways to achieve this requirement but I prefer to use SP.UserProfiles.PeopleManager Api to get it. It gives us vast option to retrieve any user information. Here are some details of getting various details: Ge...

Add welcome pop up for first time users of your site using AngularJs Material

Image
Hi Guys, We really do only have one chance for putting a first impression for end users on our website. User's will never land back to your website if there is nothing interesting found on web site. Same logic works for SharePoint sites too. When a visitor lands on your site for the first time (and maybe the last), how you welcome them will have a big impact. This can be accomplished with pop-up boxes, fullscreen welcome mats, live chat invitations, and more. This post is all about a welcome popup on SharePoint site. In brief, I try my best to provide very easy solution of showing welcome pop up. Requirement:  One of my recent project client asked to show a welcome message. Server side webarts are not promoted by out clients because our site was built in SP online. It sounds very easy but complication added by showing this pop up only once per user. Solution : As a solution, i suggested to achieve this using Content editor web part. Just place some quick JS code on the land...

Reassign a workflow task - Task update was not accepted. To edit a task associated with a workflow task process, you must be the person to whom the task is currently assigned.

Image
Hi guys, Recently one of my client has faced this issue while reassigning a task of default Approval workflow. Here is the screen shot:        SharePoint by default only allows the assignee to re-assign the task. If you try to re-assign a task that is not assigned to you, you get the following message: Task update was not accepted. To edit a task associated with a workflow task process, you must be the person to whom the task is currently assigned. Solution To overwrite this behaviour: Open SharePoint Designer Open the Workflow you wish to modify. On the step where you start the workflow task ‘Start <workflow task name> process on Current Item with…’, right click on the task name. Select Properties and look for the attribute  TaskProcessOwner . Click on the ‘ … ‘ button to select a group or specific user. You may wish to create a SharePoint group specifically for this purpose. All members of this group will have permissions to re-assign tasks that are assigned t...

SharePoint Online/2013 Replace no results default text ‘Nothing here matches your search’ from search results web part

Image
  As we all aware, SharePoint search have great potential to provide very powerful search solution. Couple of new webparts are added in SharePoint 2013, like Content Search web part for which I should use rather a word "Smart" search web part. With a new rendering mechanism, content search webpart becomes more and more simple to edit and customize. That mechanism is called "Display Templates" and these are based upon simple Json to HTML templates. I recently has faced a project scenario, where I was asked to replace the part of search result web part and I provided a solution by updating search display template. Requirement:   When we add a search result web part on any result page along with a search text box web part to enter search keywords. Search results will be displayed in web part if keyword matches any text. When we add both these web parts on page and before entering the search term also the results web part show  “Nothing here matches your search” (as sho...

Angular 5: Intallation and configuration with Angular CLI

Image
Hi Guys, In this blog, I am sharing how one can easily install angular (version 5.2.0). Angular 6 beta is out till date, which is not yet stable. Most of developers are excited to try one of the most modern and powerful frontend JS framework. Here is the quick guide to install angular 5 with CLI on development environment. I am choosing a stable version of Angular (5.2.0) for installation purpose in this blog. Lucky, if you are familiar with Angular 2 or 4 and have good experience with it, the process of starting a new Angular 5 project is pretty much the same. However, if you are new to angular and not having previous experience with Angular, don't worry -- installing Angular 5 is like a breeze. Let's get started. Pre-requisites: Here are the list of tools which you require before proceeding. Visual Studio Code/Visual Studio - Download Node.js - Download Node Package Manager(NPM) To check whether or not you have both of these installed, visiting your commend line(Win ...

SQL Server install error Wait on the Database Engine Recovery Handle Failed

Image
Hi Guys, Last week during the installation of SQL Server standalone instance, I have faced an issue. After installing all the prerequisites and I started installing SQL Server. Though, I did not get any warnings or errors in any of the rules or steps during the SQL Server installation wizard, but I got the below error at the end of the installation: The following error has occurred: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes. This issue is giving misleading message. Well, I could not able to understand the cause of this error. I followed standard installation guide and completed pre-check before proceeding installation of SQL Server, but I still got this issue. In this blog, I will explain how did I resolved this issue. After many rounds of troubleshooting I decided to do some research on the web.  This was the first time I got this issue, so I had no clue about how to fix except for reading and analyzing the error log files....

AngularJS: Export Json object to Excel using AlaSQL

Hello, I have spent significant time developing AngularJS and Angular 2 applications. But this requirement is quite new to me. Well, user wants to export to excel feature on one of our application page where we are using filtered data based upon some parameters. The design decision was on me whether to choose server side function to convert Json object in to CSV format and then export it to excel. But I decided to choose another approach, not to involve server in exporting a Json data. I was not aware about ALASQL but later explored and found its very useful for me to implement this solution. Here I am explaining how to implement it. What you need to import : ALASQL js-xlsx Just an intro about these two libraries: AlaSQL is an open source SQL database for Javascript with a strong focus on query speed and data source flexibility for both relational data and schemaless data. It works in your browser, Node.js, and Cordova. This library is designed for: Fast in-memory SQL data pro...

AngularJS: Bind UI Select selection sequentially

Image
Hello, I felt lucky to work with angularJS with the integration with SharePoint(as backend) in my recent project. There was a requirement to have two drop-downs on a single page application where on selection of one; other drop-down value will be automatically filtered.  I am going to share with you guys that how I have implemented.  I understand that this may not be Ideal way of doing it but I am sure that it is quickest solution that I did in code to achieve this requirement. HTML: The below html will generate two dropdowns and populate with country and states data. <h3>Countries</h3> <ui-select ng-model="ctrl.country.selected" name="country" theme="bootstrap" title="Select a Country" > <ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match> <ui-select-choices repeat="country in ctrl.countries | filter: $select.search"> <span...

Not able to view result while building Search Query

Image
Hello SharePointers ;), Here is another quick finding which I just thought should be shared to save someone precious time. If you are dealing with SharePoint 2013 search and Result sources, you must try to test the query template before saving it. If you are not able to see any results instead just a red error saying below text don't get scared I have quick solution for you. “The Search display templates are not present on this site collection. To add them, you need to activate the “Search Server Web Parts and Templates” feature on the Site Collection Features page. 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. Template ‘~sitecollection/_Catalogs/masterpage/DisplayTemplates/System/Control_QueryBuilderPreview.js’ not found or has sytax errors. (Load Template: ) ” You must get frustrated because your search is properly configured, its crawling the ...

CSS Trick: Create tag icon with dynamic text width using Pure CSS

Image
Hi Guys, If you are searching for a tag icon which can be used to show few keywords on any page. Then this is the place where you can find a very simple trick to generate it with in few minutes. The icon created using this CSS trick has feature that it can take dynamic width based upon the text width. Below image is the example how it will rendered:     Click here for the Demo . Basics: Pure CSS post tags uses at least 2 CSS tricks such as CSS triangles and CSS circles . For CSS triangles you need to manipulate borders of an element that has zero height and width. CSS circle is simpler. All you need is a square element with rounded corners set to at least half the size of the element. The border radius will then merge into a circle. HTML I usually markup tags with unordered list. So the markup is fairly simple: <ul class="tags"> <li>CSS</li> <li>HTML</li> <li>Mohit</li> <li>Vashishtha</li> <li>SharePo...

SharePoint : Custom Task Email with Outlook ribbon control “Open this Task”

Image
Hi Guys, It was really interesting to work with my latest client. They had an very interesting and innovated idea to automate their manual file approval process.  The requirement was to create a multistage state machine workflow where users have privilege to approve and reject documents with some comments. It was very interesting to work with end client(as they them self don't know what they actually want). I will not go deep into the workflow but surly will come back with another post explaining it. This post is more about a requirement which I faced during the development of the workflow. Just wanted to share the design of the Workflow: Requirement:   As a user, I should have receive an email from workflow with custom subject having document name embedded to the subject where I can directly do some action like approve/reject or comment on the document. I should see a button in email "Open this task" which will redirect me to the page where I can take actions. It looks b...

SharePoint PowerShell: Upload multiple documents to sharepoint document library

Image
Hi, I was creating a script to replicate document library structure similar to Prod just in order to test the ShareGate Migration. Let me take a brief description about my scenario: Description: There is a document library present on Prod, which contains bulk document (~3000). Now I need to update metadata for all those documents using Excel sheet and ShareGate. I don't have access to the Production library and not even replicate the Library to my Dev environment as it contains some very confidential documents. Solution: I have decided to create a script which will take one template document from file system and read name of document from one of columns of excel. The script will take some time(~hours in case of thousand documents) to upload the template with the new file name. The inputs to the script will be Path of the excel which contains name of documents in one column Path of the file where the template is placed on file system Url of the sharepoint web site Name of th...

Upload a file in SharePoint using REST and c# console application

Image
Hi, In my last post , I have explained how to create a sub site using REST from and Console application. In this blog  will explain how we can upload a file, which is located in file system, will be uploaded to sharepoint Document library. So if I brief about requirement here: Need to upload a file to already created SharePoint site. Use REST(not even CSOM) will be used in order to create. API call will be send from some other machine(not SharePoint machine) which is in same domain and can access the SharePoint site. Follow the given steps to achieve the same: 1) Create a simple console application with c# selected language. 2) Next is to install the Newtonsoft.Json. Navigate to Visual studio menu: "View" > "Other Windows" > "Package Manager Console" and Then type the following: "Install-Package Newtonsoft.Json" 3) Now install RestSharp using the package manager. Type the following: "Install-Package RestSharp" 4) Now open th...

Get SharePoint search results using REST ajax call from Html

Image
Hi, We all aware the SharePoint exposed REST Api in order to perform various action at client side. There are some other ways also which a developer can adopt instead of REST(like CSOM) but that requires again client context. So it is recommenced that if we are using SharePoint Apps then use CSOM to get and update the data. Where as REST can be used in apps as well as some external applications. This blog is intended to show how user can utilize the REST api and get the SharePoint Search results. There are few pre-requisites or conditions which must be fulfilled before proceeding further. The machine where this code will be executed must have access to sharepoint site which means machine must be either in same domain or cross domain accessibility is there. Search must be configured at SharePoint server. Data must be properly crawled and you must get some results when searched for some keyword. Steps: 1) Open the Explorer or any desired location and create a text file with ant des...

Create Sub Site in SharePoint using REST and c# console application

Image
Hi, Recently, I got an requirement to create a SharePoint sub site from the some .Net application which is hosted somewhere hosted outside the SharePoint environment. It is provided that the .Net application can be added in same domain. So if I brief about requirement here: Need to create a sub site in SharePoint site collection based on some default template(later on custom template) Use REST(not even CSOM) will be used in order to create. API call will be send from some other machine(not SharePoint machine) which is in same domain and can access the SharePoint site. There are few challenges which I faces if we try to work with such kind of requirements. The authentication tokens and RequestDigest data are the crucial things to retrieve. I have explored some way to execute REST API and create a sub site without navigating to SharePoint site. Follow the given steps to achieve the same: 1) Create a simple console application with c# selected language. 2) Next is to install the New...

Enable SP.JS in publishing sites for SP 2013

Hi, In my previous post , I have explained the way to add CSOM on master page of any kind of site. But later on when testing same code with publishing site, I realized that sp.js is not loaded on publishing site by default. So in this post I will discuss how to enable sp.js in Publishing Pages in SharePoint 2013. As the SharePoint uses minimal download strategy it prevents the page to have sp.js when published but the point to note is when you open your ribbon bar (edit or unpublished state) sp.js  script gets loaded in your page . Note : SharePoint loads scripts on Demand So to solve this we can do like this : Add a script editor webpart in your page and in script tags just add the following code snippet: SP.SOD.executeFunc('sp.js', 'SP.ClientContext', alert('I have loaded the sp.js script.')); Where instead of alert method you can use any JS method and will be executed after sp.js is loaded. Happy SharePointing :).

SharePoint CSOM for beginners: Get Current User details

Image
Hi Guys, This blog is targeted to developers who are novice to the client side object model in SharePoint. SharePoint apps by default provides a basic stub for getting user details inside app. But sometimes it is required to add client side code in simple script file to get user information. I hope this information will also be helpful starters of client side object model. Pre-requisites: 1) Any version of SharePoint installed: SP 2013, SP 2010 or SP Online 2) A web application and a root site collection inside it. It does not matter whether site is team site or any other type of site.(Note: In case of publishing site you need to enable sp.js file loading ). 3) SharePoint Designer installed. Step I : Create a custom script file A script file is required in order to place CSOM code to be executed. Well, here depending upon usability user can chooses any one of these two locations to create this file: - List or Style library : It will be hard to update script file if it is placed under s...

SharePoint get followed sites using REST Api

Image
Recently I was tasked with a project requirement that the user should be able to see list of content he/she followed. To me this sounds much like using the following feature of SharePoint 2013 which allows you to follow documents, sites, people and tags. Also, we don’t want the user to navigate to his/her mySite and have a look on to the content followed. We can use the SharePoint 2013 Representational State Transfer (REST) service to do the same tasks you can do when you use the .NetCSOM, JSOM. Here I explain how to retrieve the site name and URL followed by the current user in SharePoint 2013 using a client object model (REST API and JavaScript) and displaying it in the SharePoint page. 1. Create a new page and a Content Editor Webpart (CEWP). 2. Edit the web part that was added to the page. 3. Upload your text file script into the site assests and copy the path of the text file and paste it into the Content link in CEWP. 4. Output Code The following example shows how to retrieve a...

Send message to client app part using a "PostMessage Shim"

Image
In this post, I’ll walk through how to use the postMessage api to enable cross-frame communication between your Client App Parts and the hosting SharePoint page, to make your SharePoint App Parts more dynamic and responsive to changes in the parent page. Overview In the SharePoint 2013 App Model, Client App Parts are implemented as iframes into pages hosted in App Webs or Provider Hosted web applications. Because SharePoint apps are hosted on different domains, the iframes can’t use javascript to access the parent window and get information from the hosting page. This is a good thing. You wouldn’t want a Client App Part that you installed from the marketplace to be able to see the list of customers on that List View web part that sits right next to it on the page. But it does make it very hard as a developer to give Client App Parts more dynamic page information to work with. The only contextual info a Client App Part can get is through Client App Part properties. Normal SharePoint Web...