I am trying to create calculated column using csom.
var fieldXml="<Field Name='calctest' DisplayName='calctest' StaticName='calctest' Type='Calculated' Required='FALSE' ColName='sql_variant1' Format='DateOnly' EnforceUniqueValues='FALSE' Description='weg' Indexed='FALSE' ResultType='DateTime' ReadOnly='TRUE' LCID='1033' Version='2' ><Formula>=DATE(YEAR(Approval_x0020_Date)+3,MONTH(Approval_x0020_Date)+1,DAY(Approval_x0020_Date)+5)</Formula><FormulaDisplayNames>=DATE(YEAR([Approval Date])+3,MONTH([Approval Date])+1,DAY([Approval Date])+5)</FormulaDisplayNames><FieldRefs><FieldRef Name="Approval_x0020_Date" /></FieldRefs></Field>";
olist.Fields.AddFieldAsXml(fieldXml, true, AddFieldOptions.AddToDefaultContentType);
fieldTxt.Update();
olist.Update();
clientcontext.ExecuteQuery();
After executing i am getting Error:
The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column.
when i am running same code just changing column in formula, it runs smoothly and creates calculated column perfectly.
i.e If i Use Column name=Approval Date (Static name="Approval_x0020_Date"), it will throw above error.
If I use Column name=ApprovalDate (Static name="ApprovalDate"), it will work fine.
Does anyone know why it is not accepting 2 or more than 2 words of column name.
Thanks in advance.