1

I am currently creating a SharePoint extension (with spfx), At the first lauch of the extension, I have one registration form (7 input, type string).

How can I save this data on the sharepoint site so the users can read them?

I can't use the property bag of the site because I am using modern sites, by default, scripting is disabled so I can't write data in the property bag.

Do you have a solution, a workaround, an idea to solve my problem?

Thank you :-)

  • how about using SharePoint list ? you can do CRUD operations on it ! – Gautam Sheth Aug 2 '18 at 15:56
  • 1
    I already thought about that one but I just need to save one data and it's not very optimized :/ – Selim Aug 2 '18 at 16:00
1

Use PnP library.

import { default as pnp, ItemAddResult } from "sp-pnp-js";

// add an item to the list
pnp.sp.web.lists.getByTitle("My List").items.add({
    Title: "Title",
    Description: "Description"
}).then((iar: ItemAddResult) => {
    console.log(iar);
});

OR

Call REST api in your SPFx solution to save the data to SharePoint list.

/_api/web/lists/GetByTitle('list title')/items

Demo:

private _makePOSTRequest(): void {

    const spOpts: ISPHttpClientOptions = {
      body: `{ Title: 'Developer Workbench', BaseTemplate: 100 }`
    };

    this.context.spHttpClient.post(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists`, SPHttpClient.configurations.v1, spOpts)
      .then((response: SPHttpClientResponse) => {
        // Access properties of the response object. 
        console.log(`Status code: ${response.status}`);
        console.log(`Status text: ${response.statusText}`);

        //response.json() returns a promise so you get access to the json in the resolve callback.
        response.json().then((responseJSON: JSON) => {
          console.log(responseJSON);
        });
      });
}

Refer demo here.

  • Thank you for your answer but I want to know if there is an another way than a sharepoint list for storing only one raw of data – Selim Aug 3 '18 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.