Answered 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 AM
    Moderator
     
     Answered Has Code

    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:

    http://social.technet.microsoft.com/Forums/ar/sharepoint2010programming/thread/e41f6739-a633-427c-8a46-36b4133089b1

    http://social.technet.microsoft.com/Forums/en-IE/sharepoint2010programming/thread/58e951ed-e512-4bbd-a166-c228bea1276e

    Hope this can help.