1

I am trying to add a calculated field using the AddFieldAsXML method. And below is how I constructed the field xml.

> fieldXML ="<Field ID=\"{ABB544B1-5433-4B49-A629-7B242D3548E5}\"
> DisplayName=\"Test_field\"  ResultType=\"Text\" Name=\"testfield\">" +
> "<Formula>=CONCATENATE(column1,\"_\",column2)</Formula>"
>                 + "<FieldRefs>"
>                 + "<FieldRef Name=\"column1\" />"
>                 + "<FieldRef Name=\"column2\" />"
>                 + "</FieldRefs>"
>                 + "</Field>";

When I am trying to add it, I am getting an exception "Key cannot be null".

Any help is greatly appreciated.

1
  • If there is a space in the display name of your columns then make sure to use [] around column names. Mar 4, 2020 at 10:08

1 Answer 1

1

I think you are missing Type of the Field Element. Add below to Field element in XML:

Type="Calculated"

Reference: Field element (Field).

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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