The code in the following validation example allows you to change the value in the Name property of a motor item type. Also, this code modifies the value in the Description property and changes it to a string made up of the item type (motor), the item tag, and the string 'custom validated'.
-
Implement the DoValidate method as follows:
public class class 1 : ISPELValidat
{
public string LastErrorMessage {get; privateset;}
public bool DoValidate(ISPItem objISPItem, string strPropName, object varNewValue)
{
if (objISPItem.ItemType.Name == "Motor")
{
if (varNewValue ==null || varNewValue.ToString() == string.empty)
{
LastErrorMessage = "The name field cannot be empty"; return false;
}
objISPItem.Attributes["Description"}.Value =
$"{objISPItem.ItemType.Name} {objISPItem.Attributes["ItemTag"].value} {varNewValue}";
}
return true;
}
}