cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ToFj
Advocate II
Advocate II

Set Sharepoint choice column color fill with http request

Hi everyone, 

 

I have a flow creating a Sharepoint choice column with an http request. This has been working out fine, but I would very much like to set the color fill of the answers with the flow to something like this: 

YesNO column.JPG

Does anyone know how I can achieve this or what i need to add to the request? 

This is the body I have been using so far. 

{ '__metadata':
{ 'type': 'SP.FieldChoice'},
'Title': 'Yes/No',
'FieldTypeKind': 6,
'Required': 'false',
'Choices': { 'results': ['Yes', 'No'] }
}

 

Any suggestions would be greatly appreciated. 

Tord 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User II
Super User II

Hi @ToFj,

 

You could deploy this kind of column formatting via a lot of different ways. This can for instance also be done via the interface, https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

 

However, if you want to deploy it via Power Automate I think this would be possible via a different HTTP Post request. I have used the CreateFieldAsXml method. Via this approach you can add xml for the column formatting.

 

I have prepared an example which shows that approach. In my case I am creating 3 choices which will look like this:

editingridview.png

 

1. Add a Send an HTTP request to SharePoint action. Use the POST method and use the following value for the URI field. Also notice the Content-Type header which is using UTF-8.

/_api/web/lists/getByTitle('ListName')/fields/CreateFieldAsXml

 

foodchoicefield.png

 

2. Add the following value to the Body field. Notice that I am using seperate variables for the three labels (ChoiceOne, Pizza) and for the three colours (ChoiceColorOne, sp-css-backgroundColor-red). I also added a variable for the choice field name.

{"parameters":{"__metadata":{"type":"SP.XmlSchemaFieldCreationInformation"},"SchemaXml":"<Field CustomFormatter='{&quot;elmType&quot;:&quot;div&quot;,&quot;style&quot;:{&quot;flex-wrap&quot;:&quot;wrap&quot;,&quot;display&quot;:&quot;flex&quot;},&quot;children&quot;:[{&quot;elmType&quot;:&quot;div&quot;,&quot;style&quot;:{&quot;box-sizing&quot;:&quot;border-box&quot;,&quot;padding&quot;:&quot;4px 8px 5px 8px&quot;,&quot;display&quot;:&quot;flex&quot;,&quot;border-radius&quot;:&quot;16px&quot;,&quot;height&quot;:&quot;24px&quot;,&quot;align-items&quot;:&quot;center&quot;,&quot;white-space&quot;:&quot;nowrap&quot;,&quot;overflow&quot;:&quot;hidden&quot;,&quot;margin&quot;:&quot;4px 4px 4px 4px&quot;},&quot;attributes&quot;:{&quot;class&quot;:{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceOne')}&quot;]},&quot;@{variables('ChoiceColorOne')}&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceTwo')}&quot;]},&quot;@{variables('ChoiceColorTwo')}&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceThree')}&quot;]},&quot;@{variables('ChoiceColorThree')}&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;&quot;]},&quot;&quot;,&quot;sp-field-borderAllRegular sp-field-borderAllSolid sp-css-borderColor-neutralSecondary&quot;]}]}]}]}},&quot;children&quot;:[{&quot;elmType&quot;:&quot;span&quot;,&quot;style&quot;:{&quot;line-height&quot;:&quot;16px&quot;,&quot;height&quot;:&quot;14px&quot;},&quot;attributes&quot;:{&quot;iconName&quot;:{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceOne')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceTwo')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceThree')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;&quot;]},&quot;&quot;,&quot;&quot;]}]}]}]}}},{&quot;elmType&quot;:&quot;span&quot;,&quot;style&quot;:{&quot;overflow&quot;:&quot;hidden&quot;,&quot;text-overflow&quot;:&quot;ellipsis&quot;,&quot;padding&quot;:&quot;0 3px&quot;},&quot;txtContent&quot;:&quot;@currentField&quot;,&quot;attributes&quot;:{&quot;class&quot;:{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceOne')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceTwo')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceThree')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;&quot;]},&quot;&quot;,&quot;&quot;]}]}]}]}}}]}],&quot;templateId&quot;:&quot;BgColorChoicePill&quot;}' DisplayName='@{variables('ChoiceColumnName')}' FillInChoice='FALSE' Format='Dropdown' IsModern='TRUE' Name='@{variables('ChoiceColumnName')}' Title='@{variables('ChoiceColumnName')}' Type='Choice'><CHOICES><CHOICE>@{variables('ChoiceOne')}</CHOICE><CHOICE>@{variables('ChoiceTwo')}</CHOICE><CHOICE>@{variables('ChoiceThree')}</CHOICE></CHOICES></Field>","Options":12}}

 

usingvariables.png

 

The colour classes can be found on this great page, Reusable SharePoint Online Classes for Modern UI created by Denis Molodtsov.

 

Hope this helps a bit.

View solution in original post

2 REPLIES 2
Expiscornovus
Super User II
Super User II

Hi @ToFj,

 

You could deploy this kind of column formatting via a lot of different ways. This can for instance also be done via the interface, https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

 

However, if you want to deploy it via Power Automate I think this would be possible via a different HTTP Post request. I have used the CreateFieldAsXml method. Via this approach you can add xml for the column formatting.

 

I have prepared an example which shows that approach. In my case I am creating 3 choices which will look like this:

editingridview.png

 

1. Add a Send an HTTP request to SharePoint action. Use the POST method and use the following value for the URI field. Also notice the Content-Type header which is using UTF-8.

/_api/web/lists/getByTitle('ListName')/fields/CreateFieldAsXml

 

foodchoicefield.png

 

2. Add the following value to the Body field. Notice that I am using seperate variables for the three labels (ChoiceOne, Pizza) and for the three colours (ChoiceColorOne, sp-css-backgroundColor-red). I also added a variable for the choice field name.

{"parameters":{"__metadata":{"type":"SP.XmlSchemaFieldCreationInformation"},"SchemaXml":"<Field CustomFormatter='{&quot;elmType&quot;:&quot;div&quot;,&quot;style&quot;:{&quot;flex-wrap&quot;:&quot;wrap&quot;,&quot;display&quot;:&quot;flex&quot;},&quot;children&quot;:[{&quot;elmType&quot;:&quot;div&quot;,&quot;style&quot;:{&quot;box-sizing&quot;:&quot;border-box&quot;,&quot;padding&quot;:&quot;4px 8px 5px 8px&quot;,&quot;display&quot;:&quot;flex&quot;,&quot;border-radius&quot;:&quot;16px&quot;,&quot;height&quot;:&quot;24px&quot;,&quot;align-items&quot;:&quot;center&quot;,&quot;white-space&quot;:&quot;nowrap&quot;,&quot;overflow&quot;:&quot;hidden&quot;,&quot;margin&quot;:&quot;4px 4px 4px 4px&quot;},&quot;attributes&quot;:{&quot;class&quot;:{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceOne')}&quot;]},&quot;@{variables('ChoiceColorOne')}&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceTwo')}&quot;]},&quot;@{variables('ChoiceColorTwo')}&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceThree')}&quot;]},&quot;@{variables('ChoiceColorThree')}&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;&quot;]},&quot;&quot;,&quot;sp-field-borderAllRegular sp-field-borderAllSolid sp-css-borderColor-neutralSecondary&quot;]}]}]}]}},&quot;children&quot;:[{&quot;elmType&quot;:&quot;span&quot;,&quot;style&quot;:{&quot;line-height&quot;:&quot;16px&quot;,&quot;height&quot;:&quot;14px&quot;},&quot;attributes&quot;:{&quot;iconName&quot;:{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceOne')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceTwo')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceThree')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;&quot;]},&quot;&quot;,&quot;&quot;]}]}]}]}}},{&quot;elmType&quot;:&quot;span&quot;,&quot;style&quot;:{&quot;overflow&quot;:&quot;hidden&quot;,&quot;text-overflow&quot;:&quot;ellipsis&quot;,&quot;padding&quot;:&quot;0 3px&quot;},&quot;txtContent&quot;:&quot;@currentField&quot;,&quot;attributes&quot;:{&quot;class&quot;:{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceOne')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceTwo')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;@{variables('ChoiceThree')}&quot;]},&quot;&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;&quot;]},&quot;&quot;,&quot;&quot;]}]}]}]}}}]}],&quot;templateId&quot;:&quot;BgColorChoicePill&quot;}' DisplayName='@{variables('ChoiceColumnName')}' FillInChoice='FALSE' Format='Dropdown' IsModern='TRUE' Name='@{variables('ChoiceColumnName')}' Title='@{variables('ChoiceColumnName')}' Type='Choice'><CHOICES><CHOICE>@{variables('ChoiceOne')}</CHOICE><CHOICE>@{variables('ChoiceTwo')}</CHOICE><CHOICE>@{variables('ChoiceThree')}</CHOICE></CHOICES></Field>","Options":12}}

 

usingvariables.png

 

The colour classes can be found on this great page, Reusable SharePoint Online Classes for Modern UI created by Denis Molodtsov.

 

Hope this helps a bit.

View solution in original post

ToFj
Advocate II
Advocate II

Thank you very much @Expiscornovus. The HTTP request alternative was exactly what I needed. 

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (89,144)