Less than symbol in formula causes error in calculated column when applying site design
Pregunta
I'm producing a site design script for SharePoint Online in PowerShell using Add-SPOSiteScript as per these instructions, and I can create the script and add it to a site design without any errors. However, when I use this design to create a new SharePoint site, there is an error in two of my calculated columns in the List I'm creating. I've played around with the script a lot, and found that the root cause of this error is that these two calculated columns have formulas that contain a less-than character "<", and this results in the columns not being created from the design when the site is created.
In this instance I can reverse the logic of the formula so that I can instead use a greater-than symbol (which evidently works). However, what I want to know is, is there a way to escape the less-than character in the formula?
As an example, the following formula works, and a column is created when I use the site design:
"verb": "addSPFieldXml",
"schemaXml": "<Field Type=\"Calculated\" ResultType=\"Text\" Name=\"CalcProbability\" DisplayName=\"Probability\" Required=\"FALSE\"><Formula>=IF([Probability Value]=0.5,\"Rare\",\"Likely\")</Formula></Field>"
But if I use the formula below in the script (changing the equals symbol to less-than), the column fails to be created:
"verb": "addSPFieldXml",
"schemaXml": "<Field Type=\"Calculated\" ResultType=\"Text\" Name=\"CalcProbability\" DisplayName=\"Probability\" Required=\"FALSE\"><Formula>=IF([Probability Value]<0.5,\"Rare\",\"Likely\")</Formula></Field>"
The error I get in SharePoint online is:
The XML schema is invalid.
Once the site has been created, I can replace the formula with the original logic that uses the less-than character, so to me, this indicates that it could be a bug in the process of SharePoint Online applying the site-design to a site?
Or is this a known issue and there is a way to escape the less-than character in the formula?
Solución
Use <
instead of less than symbol. You can try below:
"verb": "addSPFieldXml",
"schemaXml": "<Field
Type=\"Calculated\"
ResultType=\"Text\"
Name=\"CalcProbability\"
DisplayName=\"Probability\"
Required=\"FALSE\">.
<Formula>=IF([Probability Value]<0.5,\"Rare\",\"Likely\")</Formula></Field>"