I need some help creating a calculated field which includes div styles in the formula. I created a list as part of a project in Visual Studio and now I'm creating all the necessary columns including some calculated fields. The formula works if you create a calculated column directly in SharePoint 2013 but the same formula is not working in Visual Studio Community 2015. I was writing the formulas in Scheme.xml.

I'll write an example below:

=IF([CustomField]="","","<DIV style=""text-align:left""><DIV style=""font-weight:bold"">Custom Field</DIV>")

The errors for the formula above are:

DIV - Tag was not closed.

text-align:left - Missing required whitespace and Missing attribute value on attribute 'left'.

font-weight:bold - Missing required whitespace and Missing attribute value on attribute 'bold'.

These kind of formulas are working perfectly when you are creating calculated columns directly in SharePoint but not in Visual Studio. Did someone had similar experience with that. I am new in Visual Studio.

Thanks in advance and best regards.


Ok, first thing I see is that yes indeed, you are opening two divs, and you only have a closing tag for one of them. So, you could add a second closing tag, but why not just combine them both into one? It seems like from your formula all you are doing is using the divs to apply styles. You could combine all the styles into one div. Also, what might be tripping things up is the way you are using quotes. I would try using double quotes to frame the entire markup, and single quotes around the style attribute.

So maybe try something like this:

=IF([CustomField]="","","<DIV style='text-align:left;font-weight:bold;'>Custom Field</DIV>")

The reason it might be working if you do it through the UI is that I believe SharePoint does some validation and correction on HTML entered that way.

  • The formula worked but without the div. The text in the calculated column is neither bold nor left aligned. Its actually somehow aligned to the right.
    – Ivica1987
    Feb 12 '16 at 8:49
  • What I wanted to say that Visual Studio didn't throw me an error but the div styles for bold and alignment weren't recognized. On the calculated column I only see normal text.
    – Ivica1987
    Feb 15 '16 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.