pnp / List-Formatting

List Formatting Samples for use in SharePoint and Microsoft Lists
https://pnp.github.io/List-Formatting/
MIT License
1.74k stars 833 forks source link

I have a question about view-samples/team-poll #838

Closed DeniseO closed 1 week ago

DeniseO commented 2 weeks ago

Hi!

I was trying to make this sample work: https://github.com/pnp/List-Formatting/tree/master/view-samples/team-poll.

Everything seems to be ok, except that when selecting an option, the record is not is not being updated. I can see the poll options, but when clicking is not saving any value, not updating any fields. I wonder if there is anything left to do on the specific columns to be updated: (selection, selectionwithcolor, responseiteration).

image

Thanks a lot for your comments!

tecchan1107 commented 2 weeks ago

Hi @DeniseO !

The result of a test in my environment

I tried it in my environment and was able to poll!

sample

⚠️ However, when I created the lookup column, it created a column with an internal name for the column that was different from the internal name written in the README.

image

Therefore, I changed some parts of the code to match the column definitions in my environment. The code after the change is as follows.

team-poll-response.json modified for my environment ``` json { "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json", "hideSelection": true, "hideColumnHeader": true, "commandBarProps": { "commands": [ { "key": "new", "hide": true } ] }, "rowFormatter": { "elmType": "div", "style": { "display": "=if(@rowIndex>0,'none','flex')", "flex-direction": "column", "border-style": "solid", "border-width": "2px", "border-radius": "12px", "width": "350px", "overflow": "hidden", "align-items": "center", "align-self": "center" }, "attributes": { "class": "ms-fontColor-neutralPrimary ms-borderColor-neutralTertiary ms-bgColor-neutralTertiary ms-fontSize-l" }, "children": [ { "COMMENT": "POLL TITLE", "elmType": "div", "txtContent": "[$Poll.lookupValue]", "style": { "width": "100%", "text-align": "center", "padding": "4px" }, "attributes": { "class": "ms-fontColor-white ms-fontSize-m ms-fontWeight-semibold" } }, { "COMMENT": "UNCONFIGURED MESSAGE", "elmType": "div", "attributes": { "class": "ms-bgColor-white ms-fontSize-m" }, "style": { "display": "=if([$User],'none','flex')", "flex-direction": "column", "width": "100%", "align-items": "center", "padding": "6px" }, "children": [ { "elmType": "div", "style": { "width": "332px" }, "txtContent": "This poll is not yet configured for your account. If you were recently added, please give it some time. Otherwise, contact the site owner." } ] }, { "elmType": "div", "attributes": { "class": "ms-bgColor-white" }, "style": { "display": "=if([$User],'flex','none')", "flex-direction": "column", "width": "100%", "align-items": "center" }, "children": [ { "COMMENT": "QUESTION", "elmType": "div", "txtContent": "[$Poll_x003a__x0020_Question]", "attributes": { "class": "ms-fontWeight-semibold" }, "style": { "padding-top": "12px" } }, { "COMMENT": "OPTION 1", "elmType": "div", "style": { "display": "=if([$Poll_x003a__x0020_Option1]=='','none','flex')", "padding": "12px", "column-gap": "6px", "width": "332px", "justify-content": "center", "cursor": "pointer" }, "attributes": { "class": "='ms-bgColor-neutralLight--hover' + if([$Selection]==[$Poll_x003a__x0020_Option1] && [$ResponseIteration]>=[$Poll_x003a__x0020_Iteration],' ms-bgColor-themeLighter','')" }, "customRowAction": { "action": "setValue", "actionInput": { "Selection": "=if([$Selection]==[$Poll_x003a__x0020_Option1],'',[$Poll_x003a__x0020_Option1])", "ResponseIteration": "[$Poll_x003a__x0020_Iteration]", "SelectionwithColor": "=if([$Selection]==[$Poll_x003a__x0020_Option1],'',[$Poll_x003a__x0020_Option1] + '|+|' + [$Poll_x003a__x0020_Color1])" } }, "children": [ { "elmType": "div", "txtContent": "=if([$Selection]==[$Poll_x003a__x0020_Option1] && [$ResponseIteration]>=[$Poll_x003a__x0020_Iteration],'✔ ','') + [$Poll_x003a__x0020_Option1]", "style": { "text-align": "center" } } ] }, { "COMMENT": "OPTION 2", "elmType": "div", "style": { "display": "=if([$Poll_x003a__x0020_Option2]=='','none','flex')", "padding": "12px", "column-gap": "6px", "width": "332px", "justify-content": "center", "cursor": "pointer" }, "attributes": { "class": "='ms-bgColor-neutralLight--hover' + if([$Selection]==[$Poll_x003a__x0020_Option2] && [$ResponseIteration]>=[$Poll_x003a__x0020_Iteration],' ms-bgColor-themeLighter','')" }, "customRowAction": { "action": "setValue", "actionInput": { "Selection": "=if([$Selection]==[$Poll_x003a__x0020_Option2],'',[$Poll_x003a__x0020_Option2])", "ResponseIteration": "[$Poll_x003a__x0020_Iteration]", "SelectionwithColor": "=if([$Selection]==[$Poll_x003a__x0020_Option2],'',[$Poll_x003a__x0020_Option2] + '|+|' + [$Poll_x003a__x0020_Color2])" } }, "children": [ { "elmType": "div", "txtContent": "=if([$Selection]==[$Poll_x003a__x0020_Option2] && [$ResponseIteration]>=[$Poll_x003a__x0020_Iteration],'✔ ','') + [$Poll_x003a__x0020_Option2]", "style": { "text-align": "center" } } ] }, { "COMMENT": "OPTION 3", "elmType": "div", "style": { "display": "=if([$Poll_x003a__x0020_Option3]=='','none','flex')", "padding": "12px", "column-gap": "6px", "width": "332px", "justify-content": "center", "cursor": "pointer" }, "attributes": { "class": "='ms-bgColor-neutralLight--hover' + if([$Selection]==[$Poll_x003a__x0020_Option3] && [$ResponseIteration]>=[$Poll_x003a__x0020_Iteration],' ms-bgColor-themeLighter','')" }, "customRowAction": { "action": "setValue", "actionInput": { "Selection": "=if([$Selection]==[$Poll_x003a__x0020_Option3],'',[$Poll_x003a__x0020_Option3])", "ResponseIteration": "[$Poll_x003a__x0020_Iteration]", "SelectionwithColor": "=if([$Selection]==[$Poll_x003a__x0020_Option3],'',[$Poll_x003a__x0020_Option3] + '|+|' + [$Poll_x003a__x0020_Color3])" } }, "children": [ { "elmType": "div", "txtContent": "=if([$Selection]==[$Poll_x003a__x0020_Option3] && [$ResponseIteration]>=[$Poll_x003a__x0020_Iteration],'✔ ','') + [$Poll_x003a__x0020_Option3]", "style": { "text-align": "center", "cursor": "pointer" } } ] } ] } ] } } ```
Comparison of internal names of columns in README and my environment |Internal name of the column in README|Internal name of the column in my environment| |---|---| |Poll_x003a__x0020_Option_x0020_1|Poll_x003a__x0020_Option1| |Poll_x003a__x0020_Option_x0020_2|Poll_x003a__x0020_Option2| |Poll_x003a__x0020_Option_x0020_3|Poll_x003a__x0020_Option3| |Poll_x003a__x0020_Color_x0020_1|Poll_x003a__x0020_Color1| |Poll_x003a__x0020_Color_x0020_2|Poll_x003a__x0020_Color2| |Poll_x003a__x0020_Color_x0020_3|Poll_x003a__x0020_Color3|

Causes of failure to update

As for the reason for not being able to update, I think there are two possible reasons:

No editing permission is granted

If the item cannot be edited, it cannot be updated. Please check again if the user who will update the item has editing permission.

The internal names of the columns written in the JSON do not match the actual internal names

There is a place in the JSON where it is stated which columns with internal names are to be updated. Please check to see if the internal names of the columns listed here match the actual internal names of the columns.

image

You can check the internal name of a column from the URL of the column edit page. The internal name of the column is the part of the URL after 'Field='."

image

Demo Video

I found a demo video of this sample! I am sending it for reference.

Building no-code poll application with list formatting - YouTube

DeniseO commented 2 weeks ago

Thanks a lot @tecchan1107 for your quick and detailed response. ❤️ I deleted the lists, started over following your instructions and now it is working!!

image

I did notice the internal name difference and tried to match the column name with the spacing there, but maybe I was still doing something wrong.

Now, I do get the Results view of the Poll Responses list to work. I went throughout the video instructions, applying the JSON code provided and the filters as indicated: Selection, not equal to empty, and Response Iteration, greater or equal to 0.. But I don't get to see the bar or the grouped results, just the names that match the filtering criteria.

image

I tried to make some changes on the code, but still not working. Thanks a lot for your help! Denise

tecchan1107 commented 2 weeks ago

I did notice the internal name difference and tried to match the column name with the spacing there, but maybe I was still doing something wrong. Now, I do get the Results view of the Poll Responses list to work.

I'm glad it's fixed and working well!

But I don't get to see the bar or the grouped results, just the names that match the filtering criteria.

I tried it in my environment and was able to get the bar to appear!

image

Maybe the grouping settings are incorrect and the bar is not showing; could you please check again to see if you are grouping by SelectionwithColor column?🙇‍♂️

image

(The README didn't say which columns to group by, so I'll add that later.)

DeniseO commented 2 weeks ago

@tecchan1107 I can't thank you enough! It works perfectly now. I was not grouping correctly. That was it!

Thanks for your patience and time! Denise