Skip to content

Instantly share code, notes, and snippets.

View ktskumar's full-sized avatar

Shantha Kumar T ktskumar

View GitHub Profile
@ktskumar
ktskumar / getAadUserandTenantinfo.js
Created March 12, 2020 10:18
How to get Current User AAD ID and Tenant ID from SharePoint
//getRequest method reference
//https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425
//Get the Request location from the browser URL
var path = location.href.replace(location.search, "") + "?as=json";
if (!window._isSPSitePage) //Validate the current page not a modern Site Page
console.log("User ID: " + _spPageContextInfo.aadUserId + " - Tenant ID: " + _spPageContextInfo.aadTenantId);
else { // If the current page is modern page
@ktskumar
ktskumar / getspcurrentuser.js
Last active July 7, 2023 13:58
Retrieve the Current User information from SharePoint
//getRequest method reference
//https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425
//Returns the current user information
getRequest("https://domain.sharepoint.com/sites/name/_api/web/currentuser").then(function(output){
console.log(JSON.parse(output.response));
});
//Returned Properties
//Email, Expiration, Id, IsEmailAuthenticatonGuestUser, IsHiddenInUI, IsShareByEmailGuestUser, IsSiteAdmin, LoginName,
@ktskumar
ktskumar / getspgraphuser.js
Created March 16, 2020 10:40
Get Grah User using SharePoint RRST API
//getRequest method reference
//https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425
//Returns the profile and ms graph related user information
getRequest("https://domain.sharepoint.com/sites/webname/_api/SP.Directory.DirectorySession/GetGraphUser(principalName='[email protected]')")
.then(function(output){
console.log(JSON.parse(output.response));
});
//Returned Properties
@ktskumar
ktskumar / columnformattingCustomCardImage.json
Created April 17, 2020 16:56
Column Formatting in SharePoint List to show Image in Custom card
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"customCardProps": {
"formatter": {
"elmType": "img",
"style": {
"max-width": "250px"
},
// XMLHttpRequest to process get requests
function getRequest(url) {
var request = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
request.onreadystatechange = function() {
if (request.readyState !== 4) return;
if (request.status >= 200 && request.status < 300) {
resolve(request);
} else {
@ktskumar
ktskumar / m365powerplatformconnections.js
Created May 29, 2021 06:39
Microsoft PowerPlatform Connections
function getRequest(url) {
var request = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
request.onreadystatechange = function() {
if (request.readyState !== 4) return;
if (request.status >= 200 && request.status < 300) {
resolve(request);
} else {
reject({
status: request.status,
@ktskumar
ktskumar / m365powerplatformenvironments.js
Last active May 29, 2021 10:49
Access Microsoft Power Platform Environments through REST API
//Try this code in Microsoft Power Automate Home page
function getRequest(url) {
var request = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
request.onreadystatechange = function() {
if (request.readyState !== 4) return;
if (request.status >= 200 && request.status < 300) {
resolve(request);
} else {
@ktskumar
ktskumar / m365.getcheckedoutfiles.ps1
Created May 31, 2021 02:36
Fetch checked out files from SharePoint library using Microsoft 365 CLI
Write-host 'ensure logged in'
$m365Status = m365 status
if($m3656Status -eq "Logged Out"){
m365 login
}
#Initialize variables
$siteUrl ='https://contoso.sharepoint.com'
$library ='Documents'
@ktskumar
ktskumar / m365.exportallListData.ps1
Last active June 2, 2021 12:54
Export all list data from a SharePoint Site using Microsoft 365 CLI
#Export all lists properties (Specified in $listProperties variable) from the SharePoint in to CSV format
###
$outputfilepath = "<PUTYOURPATHHERE.csv>"
$weburl = "https://contoso.sharepoint.com/"
# Provide List Properties in below variable
$listProperties = @('Title', 'Url', 'Id')
###
Write-host 'ensure logged in'
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
@ktskumar
ktskumar / upgradespfxtov1.12.1.json
Created June 3, 2021 06:38
Upgrade SPFX v1.10.x to V1.12.1
Execute in bash
-----------------------
npm un -S @types/webpack-env @types/es6-promise
npm un -D @types/chai @types/mocha
npm i -SE @microsoft/[email protected] @microsoft/[email protected] @microsoft/[email protected] @microsoft/[email protected] @microsoft/[email protected]
npm i -DE @microsoft/[email protected] @microsoft/[email protected] @microsoft/[email protected] @microsoft/[email protected] [email protected] @microsoft/[email protected] @types/[email protected] @types/[email protected]
npm dedupe
rm ".editorconfig"
./config/copy-assets.json