Using Flexible layouts: The JSON value could not be converted to System.Int32
Category
- [x] Bug
Describe the bug
I'm using the PnP.Core and PnP.Framework 1.15.135-nightly
When creating a template with flexible Layout it gives the error "The JSON value could not be converted to System.Int32. Path: $.flexibleLayoutPosition.lg.h | LineNumber: 0 | BytePositionInLine: 367."
This happens due to the properties should be integers and in my object, one of them is not (the "h":4.4186046511627906).
{"position":{"layoutIndex":1,"zoneIndex":5,"zoneId":"d310b4b8-0dba-4778-a199-717087cd01fb","sectionIndex":2,"sectionFactor":6,"controlIndex":1},"emphasis":{"zoneEmphasis":0},"id":"6f9d5119-ef3d-4e79-bf64-86038da7520b","controlType":4,"isFromSectionTemplate":false,"addedFromPersistedData":true,"flexibleLayoutPosition":{"lg":{"x":5,"y":5,"w":22,"h":4.4186046511627906,"dataVersion":"1.0"}},"contentVersion":5}
Can this be changed to double? Are there any implications of changing this?
I changed the type to double and got the template and applied it to a site collection, and tried to edit the page which gave me the following error:
I think this may be related, but I need some confirmation.
@czullu: can you have a look at this one?
@czullu: can you have a look at this one?
Yes, will try to have a look on Friday.
@PedroMordeP - as all was reverse engineered i can neither confirm nor deny, but i will try to reproduce. After all we should be able to see what happens in Column CanvasControl1 of Pages-library. If you have time you might want to change the value directly to 4 in canvascontrol1 and see if edit of page is possible after.
@czullu I reverted the types to int and changed all the double values to int, and applied the template again. When editing the page still gives errors
I removed from all CanvasControl the property "flexibleLayoutPosition" and it still breaks.
So changing the Int to long doesn't affect it, and this may need to be changed to support decimal values when "building" the template.
Looking better at the errors found this
So I was looking into the template and removing this
<pnp:CanvasControl WebPartType="Custom" JsonControlData="{"controlType":1,"id":"emptySection","position":{"controlIndex":0,"zoneIndex":6,"sectionIndex":2,"sectionFactor":6,"layoutIndex":1,"zoneId":"5549dae9-c824-4b78-a97d-bad499c35ba8"},"emphasis":{"zoneEmphasis":0}}" ControlId="abb0a64a-4cac-4a79-883e-b4f1d9431c72" Order="1" Column="2" />
JsonControlData Decoded
{"controlType":1,"id":"emptySection","position":{"controlIndex":0,"zoneIndex":6,"sectionIndex":2,"sectionFactor":6,"layoutIndex":1,"zoneId":"5549dae9-c824-4b78-a97d-bad499c35ba8"},"emphasis":{"zoneEmphasis":0}}
The page is working better and I can edit it. The id is "emptySection", shouldn't this be a GUID?
(Edited) Found this here, can this be changed?
@PedroMordeP the pull request for pnp.core and pnp.framework to change from int to double are commited. As for your question about the emptysection webpart - if i create a new page remove all webparts and just have empty sections on that page, then ms seems to add this webpart. in my case this webpart has still the id emptySection - so i think it's still correct. But as soon as there is a webPart in the section, the emptySection webPart should be removed - at least thats the way it behaves on my tenant. I think the error was in CanvasColumn.ToHtml() - if you did load a page with a EmptySection and then add WebParts, it would still write the EmptySection as it would be in the Page Model.
@czullu Thank you for the changes. In my case, it seems when editing the page the emptysection is still there and gives that error. My first test was adding a GUID to the ID and deploy the template and the editing worked. I will do more tests and give some feedback about the emptysection without changing it.
Thank you
@PedroMordeP : I've merged the PR from @czullu , can you test again?
@jansenbe all the changes fixed my issues and i also commented here about the page not being editable, but i end up making my own changes, like i said in the comment, and i'm working with that and is all working well at the moment.
I just don't understand the revert changes done by @gautamdsheth because my initial issue was the conversion of the values.