Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / Ensure a SharePoint Folder Path using PnPJS.ts
Last active Nov 12, 2021
Create/Ensure a SharePoint folder path with nested folders using PnPJS
View Ensure a SharePoint Folder Path using PnPJS.ts
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { IWeb, sp, Web } from "@pnp/sp/presets/all";
import { HttpRequestError } from "./@pnp/odata";
const TranslatePnPError = async (opText: string, e) => {
if (e?.isHttpRequestError) {
const json = await (<HttpRequestError>e).response.json();
const errorObject = typeof json["odata.error"] === "object" ? {...json["odata.error"]} : {...e};
@phillipharding
phillipharding / Renew Expired SharePoint ACS ClientSecret.ps1
Last active Sep 30, 2021
Renews an Expired ClientSecret for a Sharepoint Addin/ACS App Registration
View Renew Expired SharePoint ACS ClientSecret.ps1
<#
Renew An Expired Clientsecret For A Sharepoint Addin/ACS App Registration
WHEN A SHAREPOINT ADDIN/ACS APP REGISTRATION IS CREATED THE CLIENTSECRET IS SET TO EXPIRE IN 1 YEAR
THIS SCRIPT WILL RENEW AN EXPIRED CLIENTSECRET WITH A VALUE THAT EXPIRES IN 3 YEARS
.\msol-renewsharepointaddinsecret.ps1 -clientId "" -userName "" -userPassword ""
#>
param (
View camlify-filter-expressions.js
console.clear();
const isEmptyString = (s) => { return (typeof s === "undefined") || (s === null) || (s.length < 1); };
camlCompareOp = "Or";
camlPredicate = "Contains";
options = {};
options.queryByUniqueIdentifier = "90911";
//options.queryByPayrollNumber = "90919";
//options.queryByLocation = "01-001";
@phillipharding
phillipharding / spfx-get-delegated-accesstoken.md
Last active Jul 22, 2021
Use SPFx to get a Delegated Access Token for a Resource to Pass onto Azure Functions
View spfx-get-delegated-accesstoken.md

Use SPFx to get a Delegated Access Token

Note the tokenAcquisitionEvent part of the code doesn't seem to work

Using this technique you can acquire a delegated access token for a resource, SharePoint or the Graph API, and pass that token onto a HTTP triggered Azure Functions endpoint for it to use to call the appropriate API.

This is a simple re-imagination of the on-behalf-of flow involving a secured Azure Functions endpoint then executing an OAuth on-behalf-of flow to exchange the received access token for one which can be used to call an API on behalf of the calling user.

Documented originally by Paolo Pialorsi and Joel Rodrigues

@phillipharding
phillipharding / Azure AD Token using Certificate Secret.md
Last active Apr 21, 2021
Generate an Azure AD Access Token using the Client Credentials flow with a Certificate Secret to use for calling the SharePoint REST API
View Azure AD Token using Certificate Secret.md
@phillipharding
phillipharding / SharePoint PnPJS Parallel ListItem Update with Retry v2
Last active Feb 14, 2021
Better version of updating a SharePoint listitem in parallel using PnPJS with retry capability if error 409 (item has been updated by another user or process) occurs
View SharePoint PnPJS Parallel ListItem Update with Retry v2
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { sp } from "@pnp/sp/presets/all";
( async () => {
console.clear();
const itemId = 89;
const RetryHttpCall = async (fnToCall: () => Promise<any>, label: string, maxTryCount: number): Promise<any> => {
@phillipharding
phillipharding / Add and Enumerate List Folder PropertyBag Values.ts
Last active Feb 18, 2021
Add/Set and List PropertyBag Values for a List Folder
View Add and Enumerate List Folder PropertyBag Values.ts
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { spPost, SharePointQueryable } from '@pnp/sp';
import { sp } from "@pnp/sp/presets/all";
const getBody = (siteid, webid, listid, folderid, propertyName, propertyValue) => `
<Request AddExpandoFieldTypeSuffix="true" ApplicationName=".NET Library" LibraryVersion="16.0.0.0" SchemaVersion="15.0.0.0" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
<Actions>
<Method Id="62" Name="SetFieldValue" ObjectPathId="59">
@phillipharding
phillipharding / Add-ValidateUpdateListItems.js
Last active Sep 3, 2021
SharePoint REST API Add/ValidateUpdateListItems
View Add-ValidateUpdateListItems.js
See:
- https://robertschouten.com/2018/04/30/update-file-metadata-with-rest-api-using-validateupdatelistitem-method/
- http://blog.arvosys.com/2018/07/06/list-items-system-update-options-in-sharepoint-online/index.html
FieldValues =
[
// Text field (single line and note)
{ FieldName: "TextField", FieldValue: "123" },
// Number field
@phillipharding
phillipharding / SharePoint PnPJS Parallel ListItem Update with Retry
Last active Feb 14, 2021
Updates a SharePoint listitem in parallel using PnPJS with retry capability if error 409 (item has been updated by another user or process) occurs
View SharePoint PnPJS Parallel ListItem Update with Retry
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { sp } from "@pnp/sp/presets/all";
( async () => {
console.clear();
const itemId = 89;
const RetryHttpCall = async (fnToCall: () => Promise<any>, label: string, delayStart: number, maxTryCount: number): Promise<any> => {
@phillipharding
phillipharding / body.json
Created Oct 17, 2020 — forked from garrytrinder/m365-identity.sh
Create custom Azure AD identity for use with CLI for Microsoft 365 using Azure CLI
View body.json
{
"isFallbackPublicClient": true,
"publicClient": {
"redirectUris": [
"https://login.microsoftonline.com/common/oauth2/nativeclient"
]
},
"web": {
"implicitGrantSettings": {
"enableIdTokenIssuance": false