Using AddFieldAsXml with Validation
-
Friday, July 15, 2011 3:43 PM
Unable to add a Field where the DisplayName="$Resources,myResources,myDisplayName" is defined, but the Validation formula cannot be localized, and the StaticName does not work.
The following error occurs:
The formula cannot refer to another column. Check the formula for spelling mistakes or change the column to this column
Answers
-
Wednesday, July 20, 2011 7:12 AMModerator
Hi,
The error indicated that the formula refer a incorrect column name. I think first you need to make sure the Resource file you can access on server. And then confirm that the field in formula section was correct.
Like:
Guid id = Guid.NewGuid(); Guid sourceID = Guid.NewGuid(); string xmlField2 = "<Field Type=\"Calculated\" DisplayName=\"$Resources:MyResource,MyNewCalculateColum;\" EnforceUniqueValues=\"FALSE\" Indexed=\"FALSE\" Format=\"DateOnly\" ResultType=\"Number\" ReadOnly=\"TRUE\" ID=\"{" + id.ToString() + "}\" SourceID=\"{" + sourceID.ToString() + "}\" StaticName=\"$Resources:MyResource,MyNewCalculateColum;\" Name=\"$Resources:MyResource,MyNewCalculateColum;\" ColName=\"sql_variant1\" RowOrdinal=\"0\">" + "<Formula>=[Number1]+[Number2]</Formula>" + "<FieldRefs>" + "<FieldRef Name=\"$Resources:MyResource, Number1;\" /> " + " <FieldRef Name=\"$Resources:MyResource, Number2;\" /> " + " </FieldRefs>" + "</Field>";
If the embedded resource syntex doesn't work. You can also try to access the resource file and corresponding value in code behind and then append to the xml string. Follow these two link:
Hope this can help.
- Marked As Answer by Shimin HuangMicrosoft Contingent Staff, Moderator Monday, July 25, 2011 2:51 AM

