I have a managed metadata column in a list. With values in English: Brussel in french: Bruxelles.
I need to compare in the ItemUpdating event the before and after properties. I know that the before cant be used because it will return null in the item updating so I have to use the properties.ListItem.
If the user uses the UI in english, then the following code works fine, because the terms are the same.
However if the user selects french, then this wont work. because the afterproperties will be Bruxelles
private void ValidateAssignmentDate(SPItemEventProperties properties, SPListItem item)
{
string currentBudgetSection = properties.ListItem["BudgetSection"] == null ? string.Empty : properties.ListItem.GetTaxonomyFieldValue("BudgetSection").ValidatedString.ToString();
string newBudgetSection = properties.AfterProperties["BudgetSection"].ToString();
bool budgetSectionSame = newBudgetSection.Equals(currentBudgetSection);
if(!budgetSectionSame))
{
//dosomething
The extension method is: (I cant change the extension method)
public static TaxonomyFieldValue GetTaxonomyFieldValue(this SPListItem item, string fieldName)
{
TaxonomyFieldValue returnValue = null;
try
{
TaxonomyField taxonomyField = GetTaxonomyField(item, fieldName);
if (taxonomyField != null && taxonomyField.Id != null)
returnValue = item[taxonomyField.Id] as TaxonomyFieldValue;
}
catch (Exception ex)
{
throw;
}
return returnValue;
}