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.
Solved! Go to Solution.
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
2. You can check in the flow history if it is incorrect.
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='{"elmType":"div","style":{"flex-wrap":"wrap","display":"flex"},"children":[{"elmType":"div","style":{"box-sizing":"border-box","padding":"4px 8px 5px 8px","overflow":"hidden","text-overflow":"ellipsis","display":"flex","border-radius":"16px","height":"24px","align-items":"center","white-space":"nowrap","margin":"4px 4px 4px 4px"},"attributes":{"class":{"operator":":","operands":[{"operator":"==","operands":["@currentField","Ja"]},"sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont",{"operator":":","operands":[{"operator":"==","operands":["@currentField","Nein"]},"sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont",{"operator":":","operands":[{"operator":"==","operands":["@currentField",""]},"","sp-field-borderAllRegular sp-field-borderAllSolid sp-css-borderColor-neutralSecondary"]}]}]}},"txtContent":"@currentField"}],"templateId":"BgColorChoicePill"}' 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}}
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 "e; 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='{"elmType":"div","style":{"flex-wrap":"wrap","display":"flex"},"children":[{"elmType":"div","style":{"box-sizing":"border-box","padding":"4px 8px 5px 8px","overflow":"hidden","text-overflow":"ellipsis","display":"flex","border-radius":"16px","height":"24px","align-items":"center","white-space":"nowrap","margin":"4px 4px 4px 4px"},"attributes":{"class":{"operator":":","operands":[{"operator":"==","operands":["@currentField","Ja"]},"sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont",{"operator":":","operands":[{"operator":"==","operands":["@currentField","Nein"]},"sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont",{"operator":":","operands":[{"operator":"==","operands":["@currentField",""]},"","sp-field-borderAllRegular sp-field-borderAllSolid sp-css-borderColor-neutralSecondary"]}]}]}},"txtContent":"@currentField"}],"templateId":"BgColorChoicePill"}' 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}}
That should give you a column like below. Be aware, this setup does not add it to the view.
Hi @Expiscornovus,
Thank you for your answer, but I already tried exactly that and I get this error as a result:
it says that the attribute metadata is not available for the type SP.XmlSchemaFieldCreationInformation.
My flow looks just like yours:
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
2. You can check in the flow history if it is incorrect.
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='{"elmType":"div","style":{"flex-wrap":"wrap","display":"flex"},"children":[{"elmType":"div","style":{"box-sizing":"border-box","padding":"4px 8px 5px 8px","overflow":"hidden","text-overflow":"ellipsis","display":"flex","border-radius":"16px","height":"24px","align-items":"center","white-space":"nowrap","margin":"4px 4px 4px 4px"},"attributes":{"class":{"operator":":","operands":[{"operator":"==","operands":["@currentField","Ja"]},"sp-css-backgroundColor-BgCornflowerBlue sp-field-fontSizeSmall sp-css-color-CornflowerBlueFont",{"operator":":","operands":[{"operator":"==","operands":["@currentField","Nein"]},"sp-css-backgroundColor-BgMintGreen sp-field-fontSizeSmall sp-css-color-MintGreenFont",{"operator":":","operands":[{"operator":"==","operands":["@currentField",""]},"","sp-field-borderAllRegular sp-field-borderAllSolid sp-css-borderColor-neutralSecondary"]}]}]}},"txtContent":"@currentField"}],"templateId":"BgColorChoicePill"}' 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}}
Thank you, the last part without the metadata worked! 😁
User | Count |
---|---|
26 | |
13 | |
12 | |
9 | |
8 |
User | Count |
---|---|
49 | |
30 | |
23 | |
20 | |
19 |