Tuesday, December 19, 2017

How to overcome SharePoint's 5000 item limit threshold?

The best answer to this question is given on this blog, with an awesome analogy -

Courtesy -

https://sharepointmaven.com/how-to-overcome-sharepoint-5000-item-limit-threshold/

There is no more explanation beyond this blog..!!

Monday, December 18, 2017

RequestDigest value in SharePoint and it's Importance

 RequestDigest as a key through which,
  • You can GET information without using it.
  • There is some information you cannot GET without using it.
  • You need the key to PUT (POST) information in SharePoint.
When executing non-GET REST requests to the SharePoint API, you must add a valid request digest to your request. This digest proves validity of your request to SharePoint. Because this token is valid only for a limited period of time, you have to ensure that the token you have is valid, before adding it to your request or the request will fail. 

SharePoint includes a request digest token on the page in a hidden field named __REQUESTDIGEST

One of the most common approaches to work with the request digest, is to obtain it from that field and add it to the request, for example

var digest = $('#__REQUESTDIGEST').val(); $.ajax({ url: '/_api/web/...' method: "POST", headers: { "Accept": "application/json; odata=nometadata", "X-RequestDigest": digest }, success: function (data) { // ... }, error: function (data, errorCode, errorMessage) { // ... } });

Such request would work initially, but if the user would have the page open for a longer period of time, the request digest on the page would expire and the request would fail with a 403 FORBIDDEN result. By default, a request digest token is valid for 30 minutes, so before using it, you have to ensure that it's still valid. In the past you had to do this manually, by comparing the timestamp from the request digest with the current time. SharePoint Framework simplifies this process by offering you two ways of ensuring that your request has a valid request digest token.

1) Use the SPHttpClient to communicate with the SharePoint REST API

2) Retrieve valid request digest using the DigestCache service
If you can't use the SPHttpClient for communicating with the SharePoint REST API, you can obtain a valid request digest token using the DigestCache service provided with the SharePoint Framework. The benefit of using the DigestCache service over manually obtaining a valid request digest token is, that the DigestCache automatically checks if the previously retrieved request digest is still valid or not. If it's expired, the DigestCache service will automatically request a new request digest token from SharePoint and store it from subsequent requests. Using the DigestCache simplifies your code and makes your solution more robust.
To use the DigestCache service in your code, first import the DigestCache and IDigestCache types from the @microsoft/sp-http package:
Next, whenever you need a valid request digest token, retrieve a reference to the DigestCache service and call its fetchDigest method:

JavaScript Display Templates

There are 2 ways to include "JavaScript files" in SharePoint forms, web parts, lists, views -

1) Inclcude .js files in "Site Assets Library" or "Script Library".
2) Upload .js file in Master Page Gallery under "JavaScript Display Template Content Type".

Discussing more about "Javascript Display Template" -

There are 2 ways to include "JavaScript files" in SharePoint forms, web parts, lists, views -

1) Inclcude .js files in "Site Assets Library" or "Script Library".
2) Upload .js file in Master Page Gallery under "JavaScript Display Template Content Type".



JavaScript Display Template Content Type has some special Site Columns added to it that will help specify the target element (view,web-part etc..) 

Lets Look at the Steps to upload a new Js file as a new Javascript Display Template and look at the description of Site Columns.

1. Navigate to the Master Page Gallery (Site Settings -> under Web Designer Galleries -> Master Pages).

2. Select Files tab and then Upload Document.

3. Browse to the new JavaScript file that you have created and select Ok.





4. Choose Content Type as "JavaScript Display Template",
Target Control Type – By description “Target Control Type is the Type of Control that you will be using in this Display Template or JavaScript File”. For example if your Display Template or JavaScript File will be controlling the rendering of a View in a List, then the Target Control Type value should be “View”.
There are three possible options
  • Form
  • View
  • Field
Standalone – Specifies if you need to include this JavaScript File Override during view selection.Default options are
  • Override
  • Standalone
Target Scope – URL of the website this override applies to. This can be a relative path to your Site Collection or subsite.
Target List Template ID – Specify the ID of the list Template type this Override or JavaScript render applies to.
Lastly, "Publish a major version" of the js file uploaded in the master page gallery. 
Template ID List :-
  • 100   Generic list
  • 101   Document library
  • 102   Survey
  • 103   Links list
  • 104   Announcements list
  • 105   Contacts list
  • 106   Events list
  • 107   Tasks list
  • 108   Discussion board
  • 109   Picture library
  • 110   Data sources
  • 111   Site template gallery
  • 112   User Information list
  • 113   Web Part gallery
  • 114   List template gallery
  • 115   XML Form library
  • 116   Master pages gallery
  • 117   No-Code Workflows
  • 118   Custom Workflow Process
  • 119   Wiki Page library
  • 120   Custom grid for a list
  • 130   Data Connection library
  • 140   Workflow History
  • 150   Gantt Tasks list
  • 200   Meeting Series list
  • 201   Meeting Agenda list
  • 202   Meeting Attendees list
  • 204   Meeting Decisions list
  • 207   Meeting Objectives list
  • 210   Meeting text box
  • 211   Meeting Things To Bring list
  • 212   Meeting Workspace Pages list
  • 301   Blog Posts list
  • 302   Blog Comments list
  • 303   Blog Categories list
  • 1100   Issue tracking
  • 1200   Administrator tasks list
5. Since the File was upload in Master Page Gallery and we are using it in the same Site collection (not Subsite) the JS Link reference will be
~site/_catalogs/masterpage/JSLink.js
If the file was to be used in a Subsite you can use ~sitecollection URL token Instead.

Wednesday, November 15, 2017

Attach-File-Modal-Dialog-Sharepoint-2013

HTML Uploader :

<div id="FileUploaded"></div><a href="javascript:openpageindialog();">Attach Supporting Documents</a>

Script :

It opens the Attach File.aspx page in modal pop up.

function openpageindialog() {
    console.log(itemId);
    var options = {
                url: _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/AttachFile.aspx?ListId={GUID}&ItemId='+itemId,
                title: 'Add Attachment',
                width:700,
                height: 200,
                dialogReturnValueCallback: function(result, fileAdded){
console.log(result);
                if(result == SP.UI.DialogResult.OK){
                    alert("file added");
                }
            }            
            }; 
            SP.UI.ModalDialog.showModalDialog(options);
        }

Wednesday, October 25, 2017

Custom designer workflow triggers twice

If you check the workflow history, you will probably see that every time an item is added or modified, the workflow runs twice. That’s why you’re receiving two email notifications. But why is the workflow running twice for each item?
The reason for this is timing. If your workflow is very short and the SharePoint server is very slow, the first instance of the workflow may finish well before the item is fully saved and committed to SharePoint. As the item is being processed, the workflow event receiver can fire again, and start another instance of the workflow.
The solution for this problem is to add a step at the end of your workflow which will pause the workflow for a few minutes – I usually set it to 5 minutes and that seems to solve the problem.


Tuesday, October 24, 2017

Add SharePoint default file attachment to New/Edit/Disp form?

For New form:-
a)Find out the idAttachmentsRow tr.

IDATTACHMENT ROW









b)Place below highlighted code above that TR.

Code For NewForm
 
 
 
For Edit Form:-

a)Find out the idAttachmentsRow tr.
IdAttachmentRow






b)Place below highlighted code above that TR. 
Code For Edit Form
 
 
 
 

For Display Form:-
Navigation to View Item
 
 






In Default Display Page Attachment is shown but when we create any customize display form for list we are not able to see the attachment even though attachment  is  present. 
Default and Customize Display Form
 
 
 
 
 
 

Tuesday, October 3, 2017

SharePoint YES/NO column align in a single row using JSOM Javascript in list form

SharePoint choice column in list form align in a single row :-

Before



After


Assign id to the <td> tag of ms-formbody of the control and add below code in JS file and call alignChoiceColumns() inside document.ready(), it additionally delete the next empty tr .



 function alignChoiceColumns(idOfTDTag) {
            var firstRadio = $("#" + fieldName + " table tbody tr td .ms-RadioText:eq(0)");
            $("#" + fieldName + " table tbody tr td .ms-RadioText:gt(0)").appendTo($(firstRadio));
            $("#" + fieldName + " table tbody tr:gt(0)").remove();
        }

Monday, September 25, 2017

Tabbed Navigation in Sharepoint Custom List forms using JQuery

Below are the steps:

1.       Download Jquery from Jquery.com
2.       Add this to Sharepoint All files Folder or Site Assets.
3.     Create new Custom Form (Newform.aspx)
5.       Add the Following Tab code in your Custom form
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Tab1</a></li>
        <li><a href="#tabs-2">Tab2</a></li>
       
              </ul>
    <div id="tabs-1">
                   <table border="0" cellspacing="0" width="100%">

                   </table>
              </div>
    <div id="tabs-2">
                   <table border="0" cellspacing="0" width="100%">

                   </table>
              </div>
  
</div>

6.       Cut the Column <Tr> from you list and paste under tabs table.

7.       Save this form and preview in browser
8.       Edit this page after clicking page tab
9.       And add two HTML form web parts on that page
10.       Edit first html web part properties and click source editor button, it will open a window copy and paste the jquery and CSS reference in this window.

In my case I have added this jquery folder to Site Assets.

<link type="text/css" href="SiteUrl/SiteAssets/jquery-ui-1.8.18.custom/css/redmond/jquery-ui-1.8.18.custom.css" rel="stylesheet" />    
<script type="text/javascript" src=" SiteUrl /SiteAssets/jquery-ui-1.8.18.custom/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src=" SiteUrl /SiteAssets/jquery-ui-1.8.18.custom/js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript">
            $(function(){
                // Tabs
                $('#tabs').tabs();   
            });
</script>
11.       Save the page and Stop editing your Tabs are ready.


Tuesday, August 1, 2017

Export SharePoint Group Users Into Excel 2013 Using OData And REST API

Prerequisites:
  1. SharePoint 2013 On-prem or O365 site, where you have sufficient permissions to perform REST query.
  2. MS Excel 2013, where you already signed-in with your domain account (for On-prem) or O365 account.


Steps to export data from SharePoint to Excel
  1. Open Excel 2013.
  2. Go to ribbon, select DATA and select From Other Sources, and click on From OData Data Feed.
  3. In ‘Data Connection Wizard’ form, provide appropriate REST link (see table above) and click on Next.

    REST Link format to get SPGroup users:

    https://<Your SP2013 Site>/_api/Web/SiteGroups/getbyname('<Group Name')/Users
  4. In Next form, select ‘Users’ table and click Next.
  5. In next form provide an appropriate data connection file name & friendly name (Note: this is not excel file name), check ‘Always attempt to use this file to refresh data’ and click Finish.
  6. In last form, ensure that ‘Table’ is selected. Select worksheet (by default its existing worksheet which is open) and click OK.
  7. Users of that group will be exported to the excel sheet.
Note: We can use same steps to get data from SharePoint lists into Excel with OData Data feed and REST API by providing a valid REST query in step #3.

Monday, July 3, 2017

How to get Item type/entity using REST JQUERY


Friday, June 30, 2017

Box Shadow on table row not appearing on certain browsers

The box-shadow property works only with elements that have display: blockor display:inline-block property.

Tuesday, June 13, 2017

FILTERING LISTVIEWS WITH URL QUERY STRING

  • Basic URL filters - AllItems.aspx?FilterFields1=ColumnName&FilterValues1=ValueText
  • Filtering multiple columns - AllItems.aspx?FilterFields1=ColumnName&FilterValues1=ValueText&FilterFields2=ColumnName&FilterValues2=ValueText
  • Multiple filter values on a single column -&FilterName=______&FilterMultiValue=____;____;_____
  • Wildcard filters - &FilterName=Product&FilterMultiValue=*jet* // for all values that contains "jet".
  • Filtering on lookup columnsAllItems.aspx?FilterFields1=Product&FilterValues1=4 // where Product is a Lookup Column and '4' is the Lookup Id of the text you want to filter.

FYI - (Interner Source) - http://sharepointificate.blogspot.de/2012/12/filtering-listviews-with-url-query.html

Monday, June 12, 2017

Get folders and files of SharePoint library using REST JSOM

<script type="text/javascript" src="../../SiteAssets/Scripts/jquery.2.1.3.min.js"></script>

<html>
<body>
<ul id="root_hierarchy"></ul>
</body>
</html>

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(showHierarchy,"sp.js");

function showHierarchy(){
    $.ajax({
url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/GetByTitle('CustomGridPOC')/items?$select=folder&$expand=folder",
method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data)
        {
     
        $.each(data.d.results,function(index,folder){
        if(folder.Folder.Name != undefined)
        {
        var ulTag = $('#root_hierarchy');
        var li = $('<li/>').appendTo(ulTag);
        var a  = $('<a/>').attr('href',folder.Folder.ServerRelativeUrl).appendTo(li);
        var img = $('<img/>').attr('src','./../SiteAssets/Images/folder-icon.png').appendTo(a);
        var span = $('<span/>').text(folder.Folder.Name).appendTo(a);
        }
        });
        }
});
    }

</script>

Monday, June 5, 2017

Get Department for current user using REST API

To get the department property of the logged in user -

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=Department

To get all the properties of another user -

For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='Department')?@v='i:0%23.f|membership|user@siteurl.onmicrosoft.com'
For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='Department')?@v='domain\username'


Tuesday, May 9, 2017

Change URL of HTML page without refreshing the page - Javascript

If you would like to replace a URL without page refresh.
I need to change:

https://example.com/en/SitePages/Projects.aspx
to

https://example.com/en/SitePages/ProjectsProduction.aspx

Use 'history.pushState' like this:

history.pushState(null, null, '/en/SitePages/ProjectsProduction.aspx');

Click default "Browse" tab of ribbon on New/Edit forms to reset the ribbon instead of Edit tab - SharePoint

Write the following code in your window.onload() :- 

--------------------------------------------------------------------------------------
function ResetRibbon() {
            try {
                var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
                SelectRibbonTab("Ribbon.Read"true);
                ribbon.removeChild("Ribbon.ListForm.Display");
                ribbon.removeChild("Ribbon.ListForm.Edit");
            } catch (e)
            { }
        }

        SP.SOD.executeOrDelayUntilScriptLoaded(function () {
            try {
                var pm = SP.Ribbon.PageManager.get_instance();

                pm.add_ribbonInited(function () {
                    ResetRibbon();
                });

                var ribbon = null;
                try {
                    ribbon = pm.get_ribbon();
                }
                catch (e) { }

                if (!ribbon) {
                    if (typeof (_ribbonStartInit) == "function")
                        _ribbonStartInit(_ribbon.initialTabId, falsenull);
                }
                else {
                    ResetRibbon();
                }
            } catch (e)
            { }

        }, "sp.ribbon.js");

Clearing Person/Group Values

To clear out or empty the values in person or group columns, how you do it depends on if the column is single-value or multi-value. For ...