public static CustomValue GetValue(LoginUser loginUser, int customFieldID, int refID, bool createValue)
        {
            CustomValues values = new CustomValues(loginUser);

            values.LoadByFieldID(customFieldID, refID);

            if (values.IsEmpty)
            {
                CustomField field = CustomFields.GetCustomField(loginUser, customFieldID);
                values = new CustomValues(loginUser);
                CustomValue value = values.AddNewCustomValue();
                value.CustomFieldID = customFieldID;
                value.Value         = "";
                if (field.FieldType == CustomFieldType.PickList)
                {
                    string[] items = field.ListValues.Split('|');
                    if (items.Length > 0)
                    {
                        value.Value = items[0];
                    }
                }
                value.RefID = refID;
                if (createValue == false)
                {
                    return(value);
                }
                value.Collection.Save();
                values.LoadByFieldID(customFieldID, refID);
                return(values[0]);
            }
            else
            {
                return(values[0]);
            }
        }
        partial void BeforeRowEdit(CustomValue newValue)
        {
            CustomValue oldValue = CustomValues.GetCustomValue(LoginUser, newValue.CustomValueID);

            newValue.OrganizationID = LoginUser.OrganizationID;
            if (oldValue.Value == newValue.Value)
            {
                return;
            }
            CustomField customField = CustomFields.GetCustomField(LoginUser, newValue.CustomFieldID);
            string      format      = "Changed {0} from '{1}' to '{2}'.";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, customField.RefType, newValue.RefID, string.Format(format, customField.Name, oldValue.Value, newValue.Value));
        }
 partial void BeforeRowInsert(CustomValue newValue)
 {
     newValue.OrganizationID = LoginUser.OrganizationID;
 }