I worked on .NET C # TBB to extract fields from a schema, which in turn parses each embedded field. I use Razor Mediator in my templates to output JSON. I am very new to C # and .NET, so I use and refer to the code that my colleagues wrote in other templates. The goal of TBB is to get the exact URL of the image in one of these built-in fields after publication, and return it to the package as plain text.
In the end, it looks like it worked until I changed one of the fields in the inline circuit to multimedialink. As soon as I started Embeddedschemafields, the template builder will make an error with such a descriptive
Operation is not supported on a new item or on a null URI.
I do not know why this is happening since the code really worked. Therefore, I believe that changing one of the built-in fields of the scheme may be a criminal, but an error occurs even before you view this specific field. my code stops when fetching a component from the built-in screen:
CM.Schema schema = (engine.GetObject(comp.GetAsSource().GetValue("ID")) as CM.Component).Schema; ItemFields fields = new ItemFields(schema); foreach (ItemField field in fields) { _log.Info("top level: " + field.Name); if (field is EmbeddedSchemaField) { CM.Component c = (CM.Component)engine.GetObject(package.GetByName(Package.ComponentName)); _log.Info(" c = " + c + " content: " + c.Content + " schema: " + c.Schema); ItemFields content = new ItemFields(c.Content, c.Schema); EmbeddedSchemaField embeddedFields = (EmbeddedSchemaField)content[field.Name]; //boom MultimediaLinkField mmValue = null; ItemFields currentFields = null; foreach (ItemFields embeddedField in embeddedFields.Values) {
Does anyone have an idea?
This is the log I received from the template creator:
GetComponentImageUrl: top level: name GetComponentImageUrl: top level: division GetComponentImageUrl: top level: theme GetComponentImageUrl: top level: product GetComponentImageUrl: field.Name = Embeddedschemafield GetComponentImageUrl: c = Component tcm:11-1963 content: System.Xml.XmlElement schema: Schema tcm:11-1842-8 GetComponentImageUrl: c. Content = System.Xml.XmlElement Engine: Error in Engine.Transform Engine: Error in Engine.Transform Operation is not supported on a new item or on a null URI. at Tridion.ContentManager.Session.GetTcmUri(String uri) at Tridion.ContentManager.Session.GetObject(String uri) at Tridion.ContentManager.Session.GetObject(XmlElement linkElement)
source share