Skip to content

Instantly share code, notes, and snippets.

View ypcode's full-sized avatar

Yannick Plenevaux ypcode

View GitHub Profile
@ypcode
ypcode / Provision-Assets.ps1
Last active July 7, 2017 07:18
Provision a Hardware Requests SharePoint list to the specified site
$webUrl = "https://<tenant>.sharepoint.com/sites/<yoursite>"
If (Get-PnPContext) {} Else { Connect-PnPOnline $webUrl }
New-PnPList -Template GenericList -Title "Hardware Requests" -Url "HardwareRequests"
$hwList = Get-PnPList -Identity "Hardware Requests"
Add-PnPField -List $hwList -Type Choice -InternalName "HW_HardwareType" -DisplayName "Type" -AddToDefaultView -Required -Choices "Keyboard","Mouse","Display","Hard drive"
Add-PnPField -List $hwList -Type Number -InternalName "HW_Quantity" -DisplayName "Quantity" -AddToDefaultView -Required
$ md spfx-apponly
$ cd spfx-apponly
$ yo @microsoft/sharepoint
Let's create a new SharePoint solution.
? What is your solution name? spfx-apponly
? Which type of client-side component to create? WebPart
? What is your WebPart name? (HelloWorld) HardwareRequestForm
? What is your WebPart description?
? Which framework would you like to use?
No JavaScript framework
export interface IHardwareRequest {
title: string;
type: string;
quantity: number;
remark: string;
approved: boolean;
rejectionReason: string;
}
import pnp, { Web, NodeFetchClient } from "sp-pnp-js";
import { IHardwareRequest } from "../model/IHardwareRequest";
const HardwareRequestListTitle = "Hardware Requests";
export class HardwareRequestService {
private web: Web;
constructor (web: Web) {
import * as React from 'react';
import styles from './HardwareRequestForm.module.scss';
import { IHardwareRequestFormProps } from './IHardwareRequestFormProps';
import { escape } from '@microsoft/sp-lodash-subset';
import { TextField, Dropdown, IDropdownOption, PrimaryButton } from "office-ui-fabric-react";
import { IHardwareRequest } from "../../../model/IHardwareRequest";
import { HardwareRequestService } from "../../../services/HardwareRequestService";
import pnp from "sp-pnp-js";
//...
public onInit(): Promise<void> {
return super.onInit().then(_ => {
pnp.setup({
spfxContext: this.context
});
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list"
Right="Write" />
</AppPermissionRequests>
module.exports = function (context, req) {
context.log('Sending app-only request to Hardware Requests list.');
var siteUrl = "https://<yourtenant>.sharepoint.com/sites/<yoursite>";
var clientId = "<your client id>";
var clientSecret = "<your client secret>";
// Instantiate the service in app-only
var service = HardwareRequestService.createAppOnly(siteUrl, clientId, clientSecret);
import { IHardwareRequest } from "../model/IHardwareRequest";
import { HttpClient, HttpClientConfiguration, IHttpClientOptions, HttpClientResponse } from "@microsoft/sp-http";
// Replace these constants by your own azure function URL
export const AzureFunctionUrl = "https://your-func.azurewebsites.net/api/AddHardwareRequest";
export const AzureFunctionSiteUrl = "https://your-func.azurewebsites.net";
export class HardwareRequestProxyService {
constructor(private httpClient: HttpClient) {
import { HttpClient } from "@microsoft/sp-http";
export interface IHardwareRequestFormProps {
description: string;
httpClient: HttpClient;
}