Posts

SharePoint useful JavaScript objects, functions

There are several SharePoint inbuilt JavaScript objects / functions helps you to write script professional way and saves your time. The following are few you can explore more in SP.Init.debug.js and page sources. 1. _spPageContextInfo:   the object exists in sharePoint pages _spPageContextInfo.siteAbsoluteUrl:   returns the site collection url of the current web site. var siteUrl = _spPageContextInfo.siteAbsoluteUrl _spPageContextInfo.webAbsoluteUrl:   returns the current web site url. var webUrl = _spPageContextInfo.webAbsoluteUrl _spPageContextInfo.webServerRelativeUrl:   returns the current web relative url var webRelativeUrl = _spPageContextInfo.webServerRelativeUrl 2. SP.ScriptHelpers:   The function implemented in SP.Init.js and used across all scripts.  SP.ScriptHelpers.isNullOrEmptyString:   this method ensure the parameter is null or empty. var a; if(SP.ScriptHelpers.isNullOrEmptyString(a)) co...

Get Host site list items in SharePoint Hosted App.

Those who starts working on Apps might face issues to read host site list items. In sharepoint hosted APP using Rest API we able to query host site list items. The rest url to get host site is almost similar to get list items but we need to specify the app context and target. Make sure JQuery loaded before to execute the code in app web parts. 'use strict'; var HostUrl=""; var AppUrl==""; // load function // Intialize HostUrl, AppUrl from query strings. // call get items method $(document).ready(function () {         HostUrl= GetQueryString("SPHostUrl");        // Get Host Url from query string         AppUrl= GetQueryString("SPAppWebUrl");        // Get App Url from query string getItems("DemoList");                   ...

Get People picker properties on client side

Some times you need to get user name from people picker for sending mails, comparing to other fields , displaying some where. Below is the few tricks that are useful to get name, and other user properties from picker. Below is the simplest way to get user name from picker. $('div[title=PeoplePickerDivTitle] span span span').text() And the below is the use full to get people picker properties email, user id ..etc var userdetails = JSON.parse($('input[ID^=PeoplePickerDivStartID][ID$=HiddenInput]').val()) if(userdetails[0]){       var displayname = userdetails[0].DisplayText Var email = userdetails[0].EntityData['Email'] } above script parse the people picker hidden input data which contains user values into JSON, and will get all user properties that exists in people picker control.

Get Query String from SharePoint page

There were several JavaScript  techniques to get query strings from URL, following are the few techniques are inbuilt in SharePoint. The main aim of this article is to use inbuilt SharePoint script techniques and to get rid of writing own JavaScript logic on every time. 1.    GetUrlKeyValue GetUrlKeyValue is an inbuilt JavaScript method exists in every page, you required to pass parameter to get the query string. You get query sting from a current url or from any url that passed as parameter to the method. It accepts a string as query string, bool for encoded value and a custom url. var itemID =  GetUrlKeyValue('ID'); var itemSourc =  GetUrlKeyValue('Source'); var enSournce = GetUrlKeyValue('Source',true);                // encoded result var enSournce = GetUrlKeyValue('Source',false);                // decoded result var cId = GetUrlKeyValue('ID',false...

Hide SharePoint 2013 List form fields

Hi SharePoint buddies & lovers, after long I started to post SharePoint topics those comes my way and quite interesting ones. SharePoint developers sometimes may need to hide and show form controls in list forms. As per business rules you need to hide certain fields in new, edit, or display forms or conditionals [select country -> show states]. Here is the simple solution to hide fields using basic jQuery to catch location of the field names. We are all know that list form controls are enclosed with table row and each control and it’s field name enclosed in a table cells. New & Edit Forms In new and edit forms field names are enclosed with <nobr> tag, nearest tr of <nobr> tag represents the whole row of field. (document).ready(function() { $('nobr:contains("Location")').closest('tr').hide(); }); Display Forms In display form field names are enclosed with table cells, parent of table cell represents the whole row of ...

Page not found under global navigation

Image
               after a crazy long I came to post these article and I promise to keep posting on my lovely SharePoint and now I completely shifted to 2013.                         Within the links in global navigation Page not found- appears when editing links but this is hidden by default. This occupies space when your navigation has fixed width you got real trouble.                 To disappear Page not found- you simply on check "Show Pages" in navigation settings, but deselect "Show Pages" has causes to no new pages are not added to navigation by default and also it removes all pages links those are added by default in navigation. So keep in mind and look all navigational links before going to deselect these option. 

Save site as Template Missing!

Image
  We might go through a situation where “Save as site template” option is missing. When I opened Site Actions > Site Settings > The following option was missing. Solution Activate the feature Publishing feature will make the back. Alternative Solution We can also type the Page URL to get the Save as template page. http://server/_layouts/savetmpl.aspx  

SharePoint 2010 Modal Dialog Pop up

Modal Dialogs in SharePoint 2010 use the client library SP.UI.ModalDialog and ShowPopupDialog. We can open Dialog without leaving the page by writing simple html markup and by calling some SP.UI.ModalDialog API’s. Most simplest and an easy way to create SharePoint Modal Dialog is, calling JavaScript function and pass only URL parameter. <a href=”javascript:SP.UI.ModalDialog.ShowPopupDialog(‘/_layouts/viewlsts.aspx?isDlg=1′);” > View All Contents < /a> isDlg=1 Optional You can simply add “&IsDlg=1″ to any SharePoint URL and the chrome will be turned off. There are some parameters specially setting the width and the height of the window and a null parameter for call back function. which for now is set to null. We can create Dialog with specified hight and width like, < a href=”javascript:SP.UI.ModalDialog.ShowPopupDialog(‘/_layouts/viewlsts.aspx?isDlg=1′, null, 500, 300);” > View All Contents...

SharePoint Custom Workflow Failed on start (retrying).

recently we developed custom sequential workflow with initiation page. when we click to run workflow on initiation page, workflow status message shows failed on start (retrying). We try to find the root cause, first we analyze initiator permission level.  then we checked workflow onActivated coding block and correlation tokens of workflow activities, seems every thing fine. after long time we find the solution similarly to permissions, during workflow starting activity ( Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData) we given safe updates to true and false of workflow item on workflow onActivated event. that causes to inconsistence of item permission workflow got stopped. once we removed alowunsafeupdates of an item workflow runs smoothly.

Custom Timer Job not Taking New code changes

I find two interesting issues in SharePoint2010 Custom Timer Job, 1)         When I redeploying customer job with new code changes I find that code won’t affect. After debugging I find this as issue. Then I try to reset IIS and rebuild solution, Redeploying again and again, change feature folder name and changing timer job name, but no luck.   After wasting two hours of time I find the solution is to “reset timer job”.   Because timer job is running on locked mode. To reset to timer job I follow this PowerShell command. Restart-Service SPTimerV4 A fter each deployment I reset this timer job, there after my code executes fine. 2)       I try to access Web Config   App Setting keys in my custom timer job using “ConfigurationManager.AppSettings["xxxxxx"];   but It showing always null. after I realized that web config is running under ‘W3WP’ process, ‘OWSTIMER’ has no permissions to access web config....

How to Remove “+ Add document" from a SharePoint 2010 Document Library

Image
In previous article , we have learned how to hide upload button of document library. In this post, we will see how to remove the “ + Add document” option from the document library in SharePoint 2010. We will get some scenarios where, we will display the document library I different view and in that, we don’t want this option to be shown to the users. Because, it will allow the users to upload the documents. Suppose the below is the document library where we want to hide the Add document option   We can achieve this by the following methods 1.    Editing the WebPart 2.    Using SharePoint Designer(CSS) 3.    Using J Query 4.    By Permission level(Default) 1. Editing the WebPart Go to Edit WebPart -> Tool bar Type -> Select NoToolBar option which will hide the Add Document option 2. Using SharePoint Designer(CSS) Go to the designer and edit the page/webpart where you want to hide. Search for  class=”ms...

Hide the Upload Button of the Doucment Library

Open your site using SharePoint Designer.  Once opened, navigate to your Library and edit your default view.  (All Files -> Your Library -> Forms -> Your View.aspx , right click and select Edit File in Advanced Mode) At the bottom of the screen you will see three options Design, Split, and Code.  Select the Split option. In your code window, locate the  <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>   tag. Now, scroll down and find the closing  </asp:Content> tag.  Insert a line above the closing tag.  Place the following code into that newly created blank line. <style type="text/css">  #Ribbon\.Documents\.New\.AddDocument-Large { display:none; }  #Ribbon\.Library\.Actions\.OpenWithExplorer-Medium { display:none; } </style> Click save, then refresh your page.  The Documents tab should now be missing the Upload Document button and the Library tab should be...

PAGE NOT FOUND ERROR PAGE IN SHAREPOINT 2013

Image
Default PageNotfound\404 page   - By default, all the Publishing sites contain a default Error\404 page  “PageNotFoundError .aspx” page which is added to the “Pages” library (See below). This page can be modified to add some custom text. “Error Page” Content Type -   To allow users to Create a new 404 Error page, Publishing Sites now contain a new Content Type “ Error Page “.This Content type Inherits from “Page” Content type and has a typical layout of a Page Not found or 404 pages. To find this Content type Navigate to Site Settings -> Content Types -> Error Page. Create a New PageNotFound or 404 Page  – To Create a new 404 page admins can navigate to the “Pages” Library and under the “Files tab” select “New Document”.In the “New Document” drop-down menu select “Error Page” (see the screen below). Once you have Created a new Error Page you can modify it by simply clicking the page in the pages library and editing it. Once do...

The Server was unable to save the form at this time. Please try again.

Image
error : " The server was unable to save the form at this time. Please try again. " i got this error while i updating list item in SharePoint 2013 custom list. I am surprise, now how i fix this and what causes to happens this issue. then finally i found some reference to restart "Search Host Controller Service". As of now i don't know why we restart. for time being i tried and now its works fine without issue. you can find "Search Host Controller Service" at manage services in central administration, just stop and start.