1

Resolved

Field link not added to content type in list instance

description

I need to add content type and field to list instance in the following manere:
 
protected override void InitializeDefinition(SPGENListInstanceProperties properties)
{
properties.ContentTypes.ProvisioningMode = SPGENProvisioningMode.ExclusiveAdd;
properties.ContentTypes.Add<MyContentType>();
properties.Fields.Add<MyOtherField>( true, true);
}
 
Expected: MyContentType in list includes also MyOtherField
Result: MyContentType binded to list, MyOtherField provisioned to list, but not added to MyContentType
 
I tried to change SPGENProvisioningMode in MyContentType - same result

comments

robertovich wrote Mar 30, 2011 at 7:23 AM

This approach also adds field to the list but not to content type in list.

public class MyList: SPGENListInstance<MyList>
    {
        protected override void InitializeDefinition(SPGENListInstanceProperties properties)
        {
            properties.ContentTypes.ProvisioningMode = SPGENProvisioningMode.ExclusiveAdd;
            properties.ContentTypes.Add<MyContentType>();
        }

        protected override void OnProvisionFinalized(SPList list)
        {          
            base.OnProvisionFinalized(list);
            MyOtherField.Instance.Provision(list, true, true);
        }
    }

robertovich wrote Mar 30, 2011 at 11:32 AM

Seems it was fixed in 1.0.3

tore7506 wrote Mar 30, 2011 at 2:45 PM

My understanding (if i havent missinterpreted your request) , would be to declare the managed elements in another way. I have created a how-to for content types now, maybe that could help to understand better?

Look in [url:http://spgenesis.codeplex.com/wikipage?title=Content%20type] section 'Create a managed content type with managed field links'.

wrote Mar 30, 2011 at 2:46 PM

robertovich wrote Mar 31, 2011 at 10:33 AM

Not exact. I understand basics of SPGenesis design, but I was not succeeded to achieve consistent behavior in following scenario:
1) There is managed Content Type "CT"
2) There is managed List Instance "LI_1" with binded "CT"
3) There is managed List Instance "LI_2"
We need to provision pair "LI_1" and "LI_2" (both) on any web and "LI_1" should include lookup field "F" to "LI_2" placed on the SAME web.

Since Lookup List of "F" is different per web, we can not manipulate it as a site column, and provisioning it exclusively per each list instance "LI_1".
My Solution: "LI_1" contains single content type "CT" which does NOT have field link "F" and we add it at the same time when we provision "F" to "LI_1" in

protected override void OnProvisionFinalized(SPList list)
        {
            base.OnProvisionFinalized(list);
            F.Instance.Provision(list, true, true); // here we add F to CT in this list instance
        }
PROBLEM: On updates field F remains in list, but its link removed from content type. PLEASE ADVISE. THANKS.

robertovich wrote Mar 31, 2011 at 10:59 AM

I figured out that list.Update() called after OnProvisionBeforeFinalization and moved my code to look like:
protected override bool OnProvisionBeforeFinalization(SPList list)
        {
            MyField.Instance.Provision(list, true, true); //note: field already provisioned to list. I want only to add it to content type in list, but actualy this not happens. :(
            return true;
        }

tore7506 wrote Apr 1, 2011 at 7:52 AM

I think I understand now :-)

I have created another example in the how-to section on how you can add the field links directly inside the list content type declaratively.
Look here http://spgenesis.codeplex.com/wikipage?title=Content%20type section 'Create a managed content type with field links added only to a list content type'.

The difference from adding the field links in the managed list instance content type instead of adding them in the OnProvisionBeforeFinalization event is that they will become a part of the list instance declaration. Things that are done in the OnProvisionBeforeFinalization could be anything. However, you can as well add the field links there if you want. It's up to you to decide what's best :-)

wrote Feb 14, 2013 at 2:13 AM

wrote May 16, 2013 at 7:49 AM

wrote May 16, 2013 at 7:49 AM

wrote Jun 14, 2013 at 6:55 AM