how to create a calculated fields programmatically
-
01-01-2021 - |
题
I need to create a calculated item , which has: the ID of the item, the created date and title. How to do this combination in xml. i tried this code :
<Field Type="Calculated" DisplayName="$Resources:SiteColumns,Calculated_Title" EnforceUniqueValues="FALSE" Indexed="FALSE"
Format="DateOnly" LCID="1033" ResultType="Text" ReadOnly="TRUE" ID="{bc7b5078-a90d-47e3-b0fc-8d87c0a0721d}"
SourceID="{d10a9f52-13ca-4392-9f51-c0f25b0b929a}" StaticName="Calculated_Title" Name="Calculated_Title" ColName="sql_variant1" RowOrdinal="0" Required="FALSE" Version="13">
<Formula>=Title&" num : "&ID&" créer a "&TEXT(Created,"d-mmm-yyyy hh:ss")</Formula>
<FieldRefs>
<FieldRef Name="Created" />
<FieldRef Name="ID" />
<FieldRef Name="Title" />
</FieldRefs>
</Field>
it doesnt work with visual studio.
but if i use the OOB,with this fomula it works fine the formular :
=Title&" num : "&ID&" créer a "&TEXT(Created,"d-mmm-yyyy hh:ss")
so how to do it to have a programmaticaly calcualted filed, with correct formula using the XML.
解决方案
You can not write the ID field, it is set by SharePoint after the Item is created in the SQL server database