1

enter image description hereI am just adding some JSON code to my columns to change the text color. All columns work as expected, but one ("Doc. #", a completely vanilla single line text column) keeps removing the code immediately after saving.

Preview works and looks ok, save seems to work, but the code disappears a second or so after closing the editor.

Any advice on how to solve this?

Code used:

{
  "$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
  "elmType": "div",
  "style": {
    "color": "black"
  },
  "txtContent": "@currentField"
}
3
  • I have tried the same on single line of text field and it is working fine. are you missing something? What is the internal name of your field? Can you add any screenshot or anything what exactly you are doing? Commented Aug 20, 2019 at 7:16
  • Updated with image. Also tried changing the "#" to "number", with no effect
    – Niklas
    Commented Aug 20, 2019 at 7:40
  • Heavens, I've got a ton of work into these SharePoint lists with PowerApps and Flows that exporting / importing the list seems like a tough medicine, but again, I appreciate these suggestions. I am not seeing anything from Microsoft on this, so I guess I will keep adding the JSON back until it "sticks". Pretty frickin' annoying though. This costs me a lot of time and frustration. Thank you again for your hard work to find a workaround.
    – Mark
    Commented Mar 9, 2022 at 15:29

3 Answers 3

0

I get a 502 error if I paste your schema's URL into the browser where as alternative URLs, such as https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json do load the JSON, so I suspect that may be your issue.

1
  • That's odd, it works just fine in all my other columns. I tried your URL, same issue as before: preview works fine, no error messages when saving, but goes back to normal as soon as the editor is closed.
    – Niklas
    Commented Aug 20, 2019 at 8:47
0

I've just started using JSON so I'm probably the least qualified to answer but I have experienced a similar issue. The code I used (From microsoft) to edit the header and body would not take. Sometimes it would show me the change (in the moment) and other times it wouldn't. Regardless, when I would exit the configure screen it would revert. But I ended up getting it to go after many attempts. Here is what I observed but can't explain. Maybe this will help others figure out a real solution.

  • Notepad: I don't use a JSON editor because I don't know which sites to trust. I pasted the JSON into word so I would not have to recreate it every time. However, when I would paste it back into the configure screen, it would say the JSON was invalid. It turns out it was changing some quotation marks (") into a slanted version causing an issue. replacing the quotation mark would fix the error. On my last attempt, I pasted the string into notepad and it worked fine.

  • Close the browser tab and reopen the list instead of closing the configure screen. One time, some minor modifications were able to stick when didn't use the X to close the form. It was not repeatable to call this a fix but it was how I was able to get the header JSON to stick.

  • Switch between browsers. I use edge (which had taken the code properly about two months ago) when I first learned about JSON. Yesterday, I tried switching between chrome and edge. Because, I was unsuccessfully trying a lot of things that weren't working, I used a simpler JSON format. I don't know why but sometimes it would hold the change. I read about clearing the cookies which didn't have a noticeable effect. I also tried the F5 or the Ctrl+F5 trick to have the browser grab fresh data. regardless of method, subsequent attempts to edit the JSON or column order were equally likely to change/revert sections that I touched.

  • Bounce between Configure Layout and Edit Column before exiting. When I was entering code in Configure Layout, it did not always make a change. While in the same window, I would switch to edit column and would see that the sections that I named were visible in the list but not on the form. When I switched back to the configure layout screen, the JSON pasted would be replaced by something different. Sometimes I would re-copy my JSON string into the box and it would end up changing the screen and the form looked as intended. The last time I did this, the change took.

I'm too afraid to go back and try to replicate the issue because I don't know what was different that made the change stick and I don't want sections to revert again. It took way to long to try and get it to work.

I have another relatively new list that is giving me the same issues. I can see if these observations are consistent or if the workaround was was just chance.

0

This one has chewed up some time for me as well. After trying many of the above suggestions, I was always faced with the situation where the code would Preview and allow me to save but would revert back to the previous code or at best to a blank json field. Only way I have had success, is:

  • 1 - create your json, preview it to make sure it's working as intended and save it to your code writer or notepad for later.
  • 2 - export your List to excel
  • 3 - create a new list and import your columns and data from your spreadsheet, ensure you select the correct column types on import. You now have blank json fields for your header/footer/body.
  • 4 - And this is your first critical step, enter your json header for example, preview and hit save. If you don't get a new screen which only allows header/footer/body json editing (and you can't see your list fields any more), it's not going to save correctly. If that happens, try switching to Edit Columns, save, then renter your json and save again.
  • Exit the editor, refresh your browser and check your list has saved. As an extra confirmation step, click New, Copy Link, and paste to a new browser tab. If the list displays correctly now, you've won.
  • 6 - Bonus round - Want to edit/add json in this same list? Chances are not good, you're probably going to start from step 1 again. You seem to get one good shot at it then it won't save new code.

Good luck out there friends.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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