7

I am trying to create a new Bundle in the Event System. However, I get the following error message: Unable to save item. Unexpected namespace URI: uuid:b2054ef9-904f-49d8-8b7f-40523bb88536. Expecting: http://www.sdltridion.com/ContentManager/Bundle

I do not see a namespace property on the bundle object. I am thinking to use UpdateXML and change the namespace - but it feels wrong and feels like Tridion should be setting the correct namespace for me.

Is there another way to set this namespace?

Here is my code:

using System;
using Tridion.ContentManager;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.Extensibility.Events;

namespace EventSystemBundles
{
    [TcmExtension("AutoCreateBundle")]
    public class AutoCreateBundle : TcmExtension
    {
        public AutoCreateBundle()
        {
            Subscribe();
        }

        public void Subscribe()
        {
           // InitLog();

            // OnComponentSavePre
            EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSavePre, EventPhases.Initiated);
        }

        private static void OnComponentSavePre(Component comp, SaveEventArgs args, EventPhases phase)
        {
            string bundleFolderUri = "tcm:11-44-2";  // read from config or folder meta later...
            string bundleTypeSchemaUri = "tcm:11-461-8";
            Session session = comp.Session;

            try
            {
                TcmUri uri = new TcmUri(bundleFolderUri);
                Bundle bundle = new Bundle(session, uri);
                bundle.Title = "Bundle for " + comp.Title;
                Schema bundleSchema = (Schema)session.GetObject(bundleTypeSchemaUri);
                bundle.TypeSchema = bundleSchema;
                bundle.Save();

                //uuid:b2054ef9-904f-49d8-8b7f-40523bb88536. Expecting: http://www.sdltridion.com/ContentManager/Bundle
            }
            catch (Exception ex)
            {
                throw ex;
            }

            comp.Title = "a " + comp.Title;
        }
    }
}

2 Answers 2

7

The problem is that you are setting Bundle schema as BundleType schema. Read this to understand it better.

Basically you need to determine your "true" bundle type schema and set bundle schema you are setting as MetadataSchema

2
  • Yes, when I read 'MetadataSchema' I was not thinking this is the 'BundleType' schema as the Tridion GUI tells me. Too bad they didn't call it 'BundleTypeSchema' and remove the need for confusion...
    – robrtc
    Commented Jul 3, 2013 at 11:00
  • I removed the bundle.TypeSchema and replaced it with bundle.MetadataSchema and it works great. Thanks!
    – robrtc
    Commented Jul 3, 2013 at 12:07
4

I had a similar problem when creating bundles with the core service. Here is my working code:

    String typeSchemaId = client.GetList("tcm:0-0-7", new OrganizationalItemItemsFilterData()).Single(s => s.Title == "Bundle").Id;
    String imageworkflowschema = "tcm:4-9170-8";

    VirtualFolderData bundle = (VirtualFolderData)client.GetDefaultData(Tridion.ContentManager.CoreService.Client.ItemType.VirtualFolder, bundleFolderURI, new ReadOptions());
    bundle.Title = "Test:" + DateTime.Now.ToFileTimeUtc();
    bundle.Configuration = bundleConfigXML.ToString();
    bundle.TypeSchema = new LinkToSchemaData { IdRef = typeSchemaId };
    bundle.MetadataSchema = new LinkToSchemaData { IdRef = imageworkflowschema };
    bundle = (VirtualFolderData)client.Create(bundle, new ReadOptions());

The tricky part was finding typeSchemaId. I also confused the BundleType and the Bundle Schemas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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