0

I'm building a webpart application using SharePoint SPFx with react.

I would like to use SharePoint's multiline text field as a way to store an array. I saw this thread here which said you can convert the array into a JSON to then store as a string.

The goal is to create a updating history list. So for example when someone makes any edits on the front end of my application on submit I want to store it like this:

0:
   Action: Updated item number 3
   User: John Smith
   Date: 07/14/2020
1:
   Action: Renamed item 22
   User: Diana Jane
   Date: 07/04/2020
2:
   Action: Removed item 4 and item 15
   User: Eli Perez
   Date: 07/03/2020

I myself will create this array I just need help on how to store it to be able to then loop through and display it on another page.

0

@hisusu32 do you mean how you would write this as a JSON structure, or how you would save in a SharePoint list?

As far as I would write it in JSON:

[
  {
    Action: 'Updated item number 3',
    User: 'John Smith',
    Date: '07/14/2020'
  },
  {
    Action: 'Renamed item 22',
    User: 'Diana Jane',
    Date: '07/04/2020'
  },
  {
    Action: 'Removed item 4 and item 15',
    User: 'Eli Perez',
    Date: '07/03/2020'
  }
]

Let us know if that's what you're looking for (and next steps) so we can help.

4
  • Hi Hugo, thanks for the response. Yes this helps a bit. I saw with the multi line that you can format with JSON. Basically what I'm trying to do is store my array in a SharePoint List. I was hoping to use the multi line field to store the list. Then in the front end I would make a call to this field, loop through and display. Any ideas on best way to do this?
    – hisusu32
    Jul 14 '20 at 21:11
  • Do you mean that you'd like to store the JSON in a single multiline field in a list? Keep in mind that you're limited to 63,999 characters in a multiline field for lists (but unlimited in document libraries -- go figure). If I were doing this, I'd break each element of my JSON into individual list items, and use something like PnPjs to retrieve the list content and map each field to a serialized array. Something like this: typescript export interface IAction { Action: string; User: string; Data: string; // maybe use date here? } Jul 15 '20 at 15:17
  • Then in your method where you retrieve your content, I'd return a: typescript const actions: IAction[]; Let me know if that's something you'd like to do and I can throw some sample code together. I hope this helps? Jul 15 '20 at 15:23
  • Ah thank you for this amazing information. This is very helpful. Can you go ahead and throw up some sample code to get me started I would appreciate that. I'm familiar with PnPjs I think my biggest concern is I need this field to append so when a new action comes in it doesn't erase/update what is currently in that list item, but adds to it.
    – hisusu32
    Jul 15 '20 at 16:19

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.