-
Notifications
You must be signed in to change notification settings - Fork 3
Common Operations
Sumit Kanchan edited this page Mar 3, 2020
·
1 revision
In this I will explain the methods and their use in the SPCommonOperations Class. To install the package do
> npm i spfxhelperAnd then import the following in the code file
import { SPCommonOperations } from 'spfxhelper';- 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);- spHttpClient: object to query SharePoint
- webUrl: Url on which site query needs to be executed
- logSource: Logging can be found under same category
- 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"]);- file names: Array of file names with extensions
{
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
}- 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");- url: Url which needs to be executed
{
ok: boolean, // If the query execution is ok
result?: any, // result of the execution of the request
error?: Error // Error object if occurred
}- 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"});- url: Url which needs to be executed
- body : payload for the execution of the request
{
ok: boolean, // If the query execution is ok
result?: any, // result of the execution of the request
error?: Error // Error object if occurred
}- 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"});- url: Url which needs to be executed
- body : payload for the execution of the request
{
ok: boolean, // If the query execution is ok
result?: any, // result of the execution of the request
error?: Error // Error object if occurred
}- 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"});- url: Url which needs to be executed
- body : payload for the execution of the request
{
ok: boolean, // If the query execution is ok
result?: any, // result of the execution of the request
error?: Error // Error object if occurred
}