Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

AddFieldAsXml doesn't work for calculated fields

$
0
0
 Hi,

I'm trying to generate a calculated field (MOSS 2007) from the schemaXml of another field, that looks as shown below.
The calc field refers to another filed called "Base Num". Due to the space in the name, the internal and display name are different.

<Field Type='Calculated' DisplayName='CalcNum' Format='DateOnly' LCID='1033' ResultType='Text' ReadOnly='TRUE' ID='{cd60edd0-4750-4ac5-b7fa-50691baf3226}' SourceID='{dfdfbdc6-25b7-45d4-8b0d-71906d519225}' StaticName='ACalcNum' Name='ACalcNum' ColName='sql_variant3' RowOrdinal='0'>

<Formula>=Base_x0020_ Num</Formula><FieldRefs><FieldRef Name='Base_x0020_ Num' /></FieldRefs></Field>

When I call myList.Fields.AddFieldAsXml with the above string I get exception "The formula refers to a column that does not exist",
although Base Num does exist.

I've seen the same exception with a similar situation: after renaming a referenced field, its internal and display name are different, and adding a calculated field that refers to it will fail with the same error.

Please note that I don't build the the CAML string I'm using for AddFieldAsXml; it is simply copied from the schemaXml of another calc field. I would prefer not to change this string, becaue it might contain a complex formula and by processing it I might ruin it.

Any ideas?

Thanks in advance
Sruli Ganor


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>