2

I'm trying to update the components metadata field using core service API's.We are having around 5000 components in that few of the components metadata field was updated and remaining does not contain any value.so i'm trying to update those components which doesn't contain metadata field value.

But I am facing issue after loading the xml from component metadata xml(Component.Metadata),but in the xml i'm not able to select the the node which I need to update.

Node test  = componentFields.SelectSingleNode("//componentFields:fielname", componentFieldsNamespaceManager);

Node "test" will have null value if the components doesn't contains field value.

Please let me know is there any way to update the metadata field of the component using Core service API.

Actually I am new to Core Service Concept...can you please help me on this issue...

Thanks in Advance.

  • 1
    Post XML of your component (simplified) and code you are using to select node. This has nothing to do with CoreService so far, but plain XPath – Andrey Marchuk May 8 '14 at 14:17
3

The Fields class as seen on the Tridion Practice wiki can be quite helpful for this sort of operation, taking out the XML manipulation and providing a simple Dictionary style approach. This works for Metadata as well as the Content XML.

Here's some partial example code:

// load a component based on that schema
var component = (ComponentData)client.Read(COMPONENT_URI, DEFAULT_READ_OPTIONS);
Console.WriteLine(component.Content);

// build a magical Fields object from it
var fields = Fields.ForContentOf(schemaFields, component);

// the Intro field doesn't have a value, let's set it
fields["Intro"].Value = "This is the (new) intro";

See the full code on this link: https://code.google.com/p/tridion-practice/wiki/ChangeContentOrMetadata

| improve this answer | |
0

Component Fields without a value will indeed not have an element in the XML. You'd need to add the element (in the right place) to give it a value and then save.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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