cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SabrinaHolzer
Regular Visitor

Power Automate - Sharepoint Field Formatting with HTTP Request

I have created a flow where the creation of a new SP List is being triggered with a couple of text fields and choice fields via HTTP Request, the body looks like this:

{
"__metadata": {
"type": "SP.FieldChoice"
},
"FieldTypeKind": 6,
"Title": "@{variables('FieldName')}",
"Required": "false",
"EnforceUniqueValues": "false",
"StaticName": "@{variables('FieldName')}",
"Choices": { 'results': ['Ja', 'Nein'] }
}

Now, is there a possibility to define the background color of the field based on the choice in this HTTP Request?
I have already tried "style" and "$schema", but I always get a bad response.

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @SabrinaHolzer,

 

Just to double check. The metadata property is using two leading underscore characters, correct? __metadata.


There might be a typo in your headers. In your screenshot it looks like there is a space character between the s and e of the word verbose. Can you double check that?

 

1. This is in your screenshot

 

typoheaders.png

 

2. You can check in the flow history if it is incorrect.

 

typoheaders02.png

 

Lastly, we could try and run the same request without metadata, that should also be an option. Try the setup below.

 

Headers

{
  "Accept": "application/json;odata=nometadata",
  "Content-Type": "application/json;odata=nometadata;charset=utf-8"
}

 

Body

{"parameters":{"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;overflow&quot;:&quot;hidden&quot;,&quot;text-overflow&quot;:&quot;ellipsis&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;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;Ja&quot;]},&quot;sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;Nein&quot;]},&quot;sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont&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;txtContent&quot;:&quot;@currentField&quot;}],&quot;templateId&quot;:&quot;BgColorChoicePill&quot;}' DisplayName='@{variables('FieldName')}' FillInChoice='FALSE' Format='Dropdown' IsModern='TRUE' Name='@{variables('FieldName')}' Title='@{variables('FieldName')}' Type='Choice'><CHOICES><CHOICE>Ja</CHOICE><CHOICE>Nein</CHOICE></CHOICES></Field>","Options":12}}

 

withoutmetadata.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


View solution in original post

4 REPLIES 4
Expiscornovus
Super User
Super User

Hi @SabrinaHolzer,

 

Which method are you using from the REST API? A POST request with Fields?

 

Alternatively, you could also use a POST request with the CreateFieldAsXml. This method has a SchemaXml property which accepts xml with the CustomFormatter node.

 

Below is an example of that approach.

Btw, you can replace the &quote; by \". However the code snippet control of this forum did not like that part of my code snippet 😂

 

 

{"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;overflow&quot;:&quot;hidden&quot;,&quot;text-overflow&quot;:&quot;ellipsis&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;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;Ja&quot;]},&quot;sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;Nein&quot;]},&quot;sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont&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;txtContent&quot;:&quot;@currentField&quot;}],&quot;templateId&quot;:&quot;BgColorChoicePill&quot;}' DisplayName='@{variables('FieldName')}' FillInChoice='FALSE' Format='Dropdown' IsModern='TRUE' Name='@{variables('FieldName')}' Title='@{variables('FieldName')}' Type='Choice'><CHOICES><CHOICE>Ja</CHOICE><CHOICE>Nein</CHOICE></CHOICES></Field>","Options":12}}

 

 

createfieldsasxml.png

 

That should give you a column like below. Be aware, this setup does not add it to the view. 

 

choiceformatting.png

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Hi @Expiscornovus,

 

Thank you for your answer, but I already tried exactly that and I get this error as a result:

SabrinaHolzer_1-1650868007534.png

 

it says that the attribute metadata is not available for the type SP.XmlSchemaFieldCreationInformation.

 

My flow looks just like yours:

SabrinaHolzer_2-1650868158987.png

 

 

 

Expiscornovus
Super User
Super User

Hi @SabrinaHolzer,

 

Just to double check. The metadata property is using two leading underscore characters, correct? __metadata.


There might be a typo in your headers. In your screenshot it looks like there is a space character between the s and e of the word verbose. Can you double check that?

 

1. This is in your screenshot

 

typoheaders.png

 

2. You can check in the flow history if it is incorrect.

 

typoheaders02.png

 

Lastly, we could try and run the same request without metadata, that should also be an option. Try the setup below.

 

Headers

{
  "Accept": "application/json;odata=nometadata",
  "Content-Type": "application/json;odata=nometadata;charset=utf-8"
}

 

Body

{"parameters":{"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;overflow&quot;:&quot;hidden&quot;,&quot;text-overflow&quot;:&quot;ellipsis&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;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;Ja&quot;]},&quot;sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont&quot;,{&quot;operator&quot;:&quot;:&quot;,&quot;operands&quot;:[{&quot;operator&quot;:&quot;==&quot;,&quot;operands&quot;:[&quot;@currentField&quot;,&quot;Nein&quot;]},&quot;sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont&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;txtContent&quot;:&quot;@currentField&quot;}],&quot;templateId&quot;:&quot;BgColorChoicePill&quot;}' DisplayName='@{variables('FieldName')}' FillInChoice='FALSE' Format='Dropdown' IsModern='TRUE' Name='@{variables('FieldName')}' Title='@{variables('FieldName')}' Type='Choice'><CHOICES><CHOICE>Ja</CHOICE><CHOICE>Nein</CHOICE></CHOICES></Field>","Options":12}}

 

withoutmetadata.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Thank you, the last part without the metadata worked! 😁

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (6,419)