Forum Discussion
Alessandro_Ansa
Jun 26, 2020Copper Contributor
JSON column formatting with Flow
Hi all I'm trying to automate the build of a SharePoint list that is formatted with JSON so that I can easily reuse it on new projects. I've built a Flow that uses http requests to create the lis...
- Jun 26, 2020
Worked it out - it is achieved through the CustomFormatter property of SP.Fields
Thanks
Alessandro_Ansa
Jun 26, 2020Copper Contributor
Worked it out - it is achieved through the CustomFormatter property of SP.Fields
Thanks
- NeilMcc1400Nov 30, 2020Copper Contributor
Hey Alessandro_Ansa ,
I've been trying to achieve the same thing. Could you show an example of CustomFormatter, so I can see the JSON formatting? Thanks!
- alessandroansaDec 01, 2020Copper Contributor
Hi Neil
I first initialized a variable (which I called CustomFormatStatus) to hold all the JSON, so something like this (note the use of backslash to comment out the quote marks):
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "attributes": { "class": "=if(@currentField == \'Complete\', \'sp-field-severity--good\', if(@currentField == \'In Progress\', \'sp-field-severity--low\', if(@currentField == \'In Review\', \'sp-field-severity--warning\', if(@currentField == \'Not started\', \'sp-field-severity--severeWarning\', \'sp-field-severity--blocked\')))) + \' ms-fontColor-neutralSecondary\'" }, "children": [ { "elmType": "span", "style": { "display": "inline-block", "padding": "0 4px" }, "attributes": { "iconName": "=if(@currentField == \'Complete\', \'Accept\', if(@currentField == \'In Progress\', \'Forward\', if(@currentField == \'In Review\', \'Edit\', if(@currentField == \'Not started\', \'Warning\', \'ErrorBadge\'))))" } }, { "elmType": "span", "txtContent": "@currentField" } ] }
Then in the HTTP request I use the customformatter property to call the variable:
{ '__metadata': { 'type': 'SP.FieldChoice' }, 'Title': 'Status', 'Choices': { 'results': ['Not started', 'In Progress', 'In Review', 'Complete'] }, 'CustomFormatter': '@{variables('CustomFormatStatus')}' }