Skip to content

Common Operations

Sumit Kanchan edited this page Mar 3, 2020 · 1 revision

SharePoint Online Common Operations

In this I will explain the methods and their use in the SPCommonOperations Class. To install the package do

> npm i spfxhelper

And then import the following in the code file

import { SPCommonOperations } from 'spfxhelper';

getInstance()

  • This method was earlier used to create the object of the class as then singleton was implemented.
  • Now that has been removed and this method does not hold much meaning as it now just creates a new object. Instead you can use the new for the same
let lstOps:SPCommonOperations = SPCommonOperations.getInstance(spHttpClient, webUrl, logSource);
let lstOps:SPCommonOperations = new SPCommonOperations(spHttpClient, webUrl, logSource);

Parametrs

  • spHttpClient: object to query SharePoint
  • webUrl: Url on which site query needs to be executed
  • logSource: Logging can be found under same category

Return type: SPListOperation


getDocIconByFiles()

  • This method returns the list details based on the title passed
let commonOps: SPCommonOperations = new SPCommonOperations(this.props.spHttpClient, this.props.weburl, "SPFX");
let docIcons: IDocResponse[] = await commonOps.getDocIconByFiles(["file1.doc","file2.pdf","file3.jpg"]);

Parameter

  • file names: Array of file names with extensions

Return Type: IDocResponse[]

{
 ok: boolean,         // If the query execution is ok
 imageUrl?: string,   // Image/Icon url for the current file name
 fileName?:string,    // File name
 error?: Error        // Error object if occurred
}

queryGETResquest()

  • This method returns the result based on the query
let commonOps: SPCommonOperations = new SPCommonOperations(this.props.spHttpClient, this.props.weburl, "SPFX");
let result: ISPBaseResponse = await commonOps.queryGETResquest("full url");

Parameter

  • url: Url which needs to be executed

Return Type: ISPBaseResponse

{
 ok: boolean,         // If the query execution is ok
 result?: any,        // result of the execution of the request
 error?: Error        // Error object if occurred
}

queryPOSTRequest()

  • This method returns the result based on the query
let commonOps: SPCommonOperations = new SPCommonOperations(this.props.spHttpClient, this.props.weburl, "SPFX");
let result: ISPBaseResponse = await commonOps.queryPOSTRequest({url: "full URL", body: "Payload"});

Parameter

  • url: Url which needs to be executed
  • body : payload for the execution of the request

Return Type: ISPBaseResponse

{
 ok: boolean,         // If the query execution is ok
 result?: any,        // result of the execution of the request
 error?: Error        // Error object if occurred
}

queryMERGERequest()

  • This method returns the result based on the query
let commonOps: SPCommonOperations = new SPCommonOperations(this.props.spHttpClient, this.props.weburl, "SPFX");
let result: ISPBaseResponse = await commonOps.queryMERGERequest({url: "full URL", body: "Payload"});

Parameter

  • url: Url which needs to be executed
  • body : payload for the execution of the request

Return Type: ISPBaseResponse

{
 ok: boolean,         // If the query execution is ok
 result?: any,        // result of the execution of the request
 error?: Error        // Error object if occurred
}

queryPATCHRequest()

  • This method returns the result based on the query
let commonOps: SPCommonOperations = new SPCommonOperations(this.props.spHttpClient, this.props.weburl, "SPFX");
let result: ISPBaseResponse = await commonOps.queryPATCHRequest({url: "full URL", body: "Payload"});

Parameter

  • url: Url which needs to be executed
  • body : payload for the execution of the request

Return Type: ISPBaseResponse

{
 ok: boolean,         // If the query execution is ok
 result?: any,        // result of the execution of the request
 error?: Error        // Error object if occurred
}