This project is read-only.

Can't assign values via code


Great work, btw. I love using regex for validation. This works great in my new and edit forms.
Here's the problem. When using code to assign a value to a CustomFieldTypeRegEx field in a new item, it throws a "Object reference not set to an instance of an object.". The relevant stack trace is:
at CMS.SharePoint.CFT_RegEx.CustomFieldTypeRegEx.GetCacheKey(String propertyName)
at CMS.SharePoint.CFT_RegEx.CustomFieldTypeRegEx.GetCustomProperty(String propertyName)
at CMS.SharePoint.CFT_RegEx.CustomFieldTypeRegEx.GetValidatedString(Object value)
at Microsoft.SharePoint.SPListItem.SetValue(String strName, Object value, SPField field, Boolean protectFields)
at Microsoft.SharePoint.SPListItem.SetValue(String strName, Object value, Boolean protectFields)
at Microsoft.SharePoint.SPListItem.set_Item(String fieldName, Object value)
It seems to me the the propertyName object is the thing that is causing the problem.
I discovered this in a custom workflow that creates a new item based on the current item. I'm pretty sure that a Designer created workflow pukes on it too.


TheButcher wrote Jul 22, 2011 at 12:49 PM

Hello, i had the same problem. Go to CustomFieldTypeRegEx and change the method GetCacheKey to something similar to this
    private string GetCacheKey(string propertyName)
        string guid;
        if (SPContext.Current == null)
            guid = new Guid().ToString().GetHashCode().ToString();
            guid = SPContext.Current.GetHashCode().ToString();
        return guid + "_" + (ParentList == null ? "SITE" : ParentList.ID.ToString()) + "_" + propertyName;

wrote Feb 13, 2013 at 9:47 PM