0

I'm familiar with SharePoint Designer and have just moved to using Visual Studio. I am building a SharePoint Add-in here. I can't figure out how to add a calculated column into lists, however. The option simply isn't there. Advice, please?

0

You can create your own calculated column field definition, and then include that field in the list definition/schema (along with the other fields used in the calculation, of course).

The CAML for a calculated column looks roughly like this:

<Field ID="{900A6481-2EA0-4F7A-922D-F9596E0BF05F}"
       Name="MyCalculatedField"
       DisplayName="My Calculated Field"
       Type="Calculated"
       ResultType="Number"
       Group="My Columns">
  <Formula>=SUM([OtherColumn], [YetAnotherColumn])</Formula>
  <FieldRefs>
    <FieldRef Name="OtherColumn" />
    <FieldRef Name="YetAnotherColumn" />
  </FieldRefs>
</Field>

The key things to see here: the Type is Calculated, you will need to specify the ResultType, you can include the formula using the Formula child element, and you need to include FieldRefs for every other field you are using in the calculation.

Here is the MSDN documentation on the Field element schema.

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.