Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've created a custom field type called CompanyRule.

I've created a content type call RulesCT with four site columns that are of type CompanyRule. Initially I can give and update the values of the the custom parameters without any problem.

I created a list that used the RulesCT content type. Now when I update the custom parameters while "Update all list columns based on this site column?" is set to yes, it blanks out all of the custom parameters. If I set it to no, it works as expected. Below are two functions that seem to be where the error occurs but I can't tell what it might be. Any help would be appreciated.

    //Field is updated
    public override void OnUpdated()
    {
        SPAddFieldOptions op = SPAddFieldOptions.Default;

        String addFieldOptionPropertyValue = this.GetProperty("AddFieldOption");
        if (!String.IsNullOrEmpty(addFieldOptionPropertyValue))
        {
            op = (SPAddFieldOptions)Enum.Parse(typeof(SPAddFieldOptions), this.GetProperty("AddFieldOption"), true);
        }
        if (!this.savingSchemaXml)
        {
            this.savingSchemaXml = true;
            base.SchemaXml = this.CreateOrUpdateFieldSchemaXml(op);
            this.CleanThreadLocalStorage();
        }
    }

    //
    private string CreateOrUpdateFieldSchemaXml(SPAddFieldOptions op)
    {
        XElement schemaXmlElement = XElement.Parse(this.SchemaXml);
        schemaXmlElement.SetAttributeValue("CFDCTMID", this.GetPropertyFromThread<string>("CFDCTMID"));
        schemaXmlElement.SetAttributeValue("CFStatus", this.GetPropertyFromThread<string>("CFStatus"));
        schemaXmlElement.SetAttributeValue("CFType", this.GetPropertyFromThread<string>("CFType"));
        schemaXmlElement.SetAttributeValue("CFDefaultValue", this.GetPropertyFromThread<string>("CFDefaultValue"));
        schemaXmlElement.SetAttributeValue("CFDataSource", this.GetPropertyFromThread<string>("CFDataSource"));
        schemaXmlElement.SetAttributeValue("CFDataTable", this.GetPropertyFromThread<string>("CFDataTable"));
        schemaXmlElement.SetAttributeValue("CFLabCol", this.GetPropertyFromThread<string>("CFLabCol"));
        schemaXmlElement.SetAttributeValue("CFValCol", this.GetPropertyFromThread<string>("CFValCol"));
        schemaXmlElement.SetAttributeValue("CFParentControl", this.GetPropertyFromThread<string>("CFParentControl"));
        schemaXmlElement.SetAttributeValue("CFParentChangeQuery", this.GetPropertyFromThread<string>("CFParentChangeQuery"));
        schemaXmlElement.SetAttributeValue("CFChildControl", this.GetPropertyFromThread<string>("CFChildControl"));
        schemaXmlElement.SetAttributeValue("CFChildChangeQuery", this.GetPropertyFromThread<string>("CFChildChangeQuery"));
        schemaXmlElement.SetAttributeValue("CFEventTriggerGroup", this.GetPropertyFromThread<string>("CFEventTriggerGroup"));
        schemaXmlElement.SetAttributeValue("CFEventListenerGroup", this.GetPropertyFromThread<string>("CFEventListenerGroup"));
        schemaXmlElement.SetAttributeValue("CFEventListenerAction", this.GetPropertyFromThread<string>("CFEventListenerAction"));
        schemaXmlElement.SetAttributeValue("CFSearchOrder", this.GetPropertyFromThread<string>("CFSearchOrder"));
        schemaXmlElement.SetAttributeValue("CFUploadOrder", this.GetPropertyFromThread<string>("CFUploadOrder"));

        //TRY / CATCH in place because you can not unbox a generic of type bool when it is null - apparently
        try
        { schemaXmlElement.SetAttributeValue("CFSearchVisible", this.GetPropertyFromThread<bool>("CFSearchVisible")); }
        catch
        { schemaXmlElement.SetAttributeValue("CFSearchVisible", this.GetPropertyFromThread<string>("CFSearchVisible")); }
        try
        { schemaXmlElement.SetAttributeValue("CFUploadVisible", this.GetPropertyFromThread<bool>("CFUploadVisible")); }
        catch
        { schemaXmlElement.SetAttributeValue("CFUploadVisible", this.GetPropertyFromThread<string>("CFUploadVisible")); }

        schemaXmlElement.SetAttributeValue("AddFieldOption", op.ToString());
        return (schemaXmlElement.ToString());
    }
share|improve this question
    
Are the custom parameters captured in a custom edit control on the field definition page...i.e. do you have a custom section that displays when your custom field type is selected from the radio button list of column/field types? –  Rob D'Oria Aug 11 '11 at 22:34
add comment

1 Answer 1

up vote 0 down vote accepted

I've resolved the problem. I don't think I can fully articulate the solution but I'll do my best.

There were three scenarios that I tested. These all used a site column that was of the custom field type.

  1. I created updated the site column in the site settings section.
  2. I created a content type that used the site column. I updated the site column and set "Update all list columns based on this site column?" to No.
  3. I created a content type that used the site column. I updated the site column and set "Update all list columns based on this site column?" to Yes.

I was able to update the custom properties for option 1 and 2 but when I did it for option 3 it blanked out all the values.

After crawling through the code I found that options 1 and 2 take a different path to 3. The solution was to update the code for each field in the CreateOrUpdateFieldSchemaXml method that I posted above to:

change:

        schemaXmlElement.SetAttributeValue("CFDCTMID", this.GetPropertyFromThread<string>("CFDCTMID"));

to:

        if (String.IsNullOrEmpty("CFDCTMID"))
        {
            schemaXmlElement.SetAttributeValue("CFDCTMID", this.GetPropertyFromThread<TProperty>("CFDCTMID"));
        }
        else
        {
            schemaXmlElement.SetAttributeValue("CFDCTMID", CFDCTMID);
        }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.