Posts

SharePoint Online - Save a modern SharePoint list as a template

  Requirement : To save a modern SharePoint list as a template to xml file to add in update.xml or as a backup AND  it was very handy to copy list definition and even to migrate lists with its content. .  You will need to manually define all the columns that you want to extract with data as shown in the example below.  Here is the script: ######################################################## $targetWeb = "https://your-site.sharepoint.com/sites/collection/" ## URL of the site $clientid = "abc-abc-abc-abc-abc" #Add client id of site $clientsecret = "abcdefghijklmnopq=" #Add client secret of site $listname  =  "Employee" ######################################################## try  { Connect-PnPOnline -Url $targetWeb -AppId $clientid -AppSecret $clientsecret;          $clientContext = Get-PnPContext; Write-Host "Connection to site established: " $targetWeb;           Export-PnPListToProvisioni...

SharePoint online - 'Load More' button click event to show more items using PnPjs

Image
Requirement : There is one list called "News". Initially on page load user wants to see only 10 news items on page and after that on load more button user wants to see another 10 items to improve performance of site. So rather than loading all items in one go we can use PnPjs or REST API to achieve this. Here I am going to show you how to achieve above requirement using PnPjs. CDN paths for these files are as below: JQuery.js:  https://code.jquery.com/jquery-3.3.1.min.js e6-Promise.js:  https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.js A lightweight library that provides tools for organizing asynchronous code. fetch.js:  https://cdnjs.cloudflare.com/ajax/libs/fetch/3.0.0/fetch.js This JavaScript is a Promise-based mechanism to request web from browser programmatically. PnP.js:  https://cdnjs.cloudflare.com/ajax/libs/sp-pnp-js/3.0.10/pnp.min.js Note:  Please add script references of above JS files in the same order as provided above. Logic :...

SPFx - Display export buttons for Excel, CSV, PDF, Copy, Print, Column visibility in Datatable.net using Typescript

This is an example to display export buttons in datatables.net using typescript in SPFx. Install following references using 'npm'. npm install jquery npm install jquery-ui npm install datatables.net npm install  datatables.net-buttons npm install datatables.net-buttons-dt npm install jszip npm install pdfmake Import references in webpart file . import * as $ from 'jquery'; import 'jquery-ui'; import 'DataTables.net'; import 'datatables.net-buttons'; import 'datatables.net-buttons-dt'; import 'pdfmake/build/pdfmake'; import * as JSZip from 'jszip'; //most important for excel button //Export to PDF import pdfMake from "pdfmake/build/pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; pdfMake.vfs = pdfFonts.pdfMake.vfs; // most important for PDF Now give reference to the webpart file .  require('../../../node_modules/datatables.net-dt/css/jquery.dataTables.min.css'); require('../../../n...

SharePoint Online : Get List settings properties using PowerShelll

Image
  Requirement : Loop through all subsite and site collection to get list settings properties. ********************************************************************************************************************** ####################################################################################### $Username = "ABC@domain-name.com" $Password = ConvertTo-SecureString -String "*******" -AsPlainText -Force $Credentials = New-Object System.Management.Automation.PSCredential ($Username, $Password) $targetWeb = "https://abc.sharepoint.com/sites/sitecollection" ## URL of the site you are uploading to $clientid = "abc-abc-abc-abc-abc" #Add client id of site $clientsecret = "abcdefghijklmnopq=" #Add client secret of site ######################################################################################### try { Connect-PnPOnline -Url $targetWeb -AppId $clientid -AppSecret $clientsecret Write-Host "Connection to site established:...

Exclude lists in search result from sites and subsites in SharePoint using PowerShell

Requirement :  Loop Through All Subsites in a Site Collection using PowerShell and exclude lists from search results (set property NoCrawl = True) Manual approach to exclude lists from search index: List Settings -> Advanced Settings -> set 'Allow items from this document library to appear in search results' to No PowerShell Script to Iterate Through All Subsites in a Site Collection in SharePoint Online: ***************************************************************************************************************************** ####################################################################################### $Username = "ABC@domain-name.com" $Password = ConvertTo-SecureString -String "*******" -AsPlainText -Force $Credentials = New-Object System.Management.Automation.PSCredential ($Username, $Password) $targetWeb = "https://abc.sharepoint.com/sites/sitecollection" ## URL of the site you are uploading to $clientid = "abc-abc-abc-ab...

Rest API for Delete Yammer Comments

Yammer is providing  Documentation  on Rest API and they are very proactive in updating those over time period. I was working on rest API for delete yammer comment in my SharePoint site using   jQuery. Rest API : https://www.yammer.com/api/v1/messages/:message_id here, message_Id : numeric value of message id Method : Delete Let me explain this with one example : function deleteComment ( MessagePostId ) { var result = confirm( "Are you sure you want to delete this Comment?" ); if (result) { yam.platform.request({ url : "https://api.yammer.com/api/v1/messages/" + MessagePostId, method : "DELETE" , async : false , beforeSend : function ( xhr ) { xhr.setRequestHeader( 'Authorization' , token) }, success : function ( res ) { alert( "The Comment has been deleted." ); //Code to remove item from array and display rest of the comment ...

How to Set Up Google Analytics Event Tracking With Google Tag Manager (GTM)

Image
I recently worked on GA for my site. So I thought to share it with you guys. (By the way this is my first blog 😃) You can track users' interactions in site like button click, link click, scrolling, form submission, PDF downloads etc.. Event tracking allows you to send event user-triggered interactions to Google Analytics. Every event can have 4 fields/data points: • Event Category (required) • Event Action (required) • Event Label (optional) • Value (optional) Event Category is the broadest value and as you go deeper, they get narrower, for example: 1. Category – form 2. Action – newsletter subscription 3. Label – sitename.com/blog/article-page 4. Value – 1 Steps to add Tags, Events and user defined variable. 1. Log into Google Tag Manager. 2. Select “Tags” from the left-hand side. 3. Create a new tag. 4. Select Universal Analytics from Tag Type. 5. Set your Google Analytics Tracking ID. 6. Choose “Event” for the track type. 7. Set your Event Category, Action, Labe...