5

I have following code for creating new Component in Tridion:

 ComponentData componentData = (ComponentData)client.Create(component, new ReadOptions());

However, once I try to read Component.Id property, it is returning new TCM URI (tcm:0-0-0). No need to say that I tried to set flags for ReadOptions or even SynchronizationOptions, but nothing seems to work. Also, I don't want to read Component again after save, I just want ID to return.

1
  • For clarity: are you testing component.Id or componentData.Id? The first is the delta object you pass in (delta compared to default values) and may indeed have a tcm:0-0-0 identifier. The latter is the created Component’s data and that is expected to have a regular TCM URI. Sep 27 '17 at 18:33
9

This is expected behavior, you will get an ID after a Save. You don't really need to "read Component again", as the Save (or Update) method returns a IdentifiableObjectData, so you can do something along the lines of:

componentData = (ComponentData)client.Save(whateverGoesInHereCan'tRemember);
4
  • 1
    Exactly, It persists the component data in the database only when you call save() and generates a new tcm id
    – Rajesh
    Sep 27 '17 at 7:52
  • Actually, I used following method with default read options, and it still returns new tcmuri: ComponentData componentData = (ComponentData)client.Save(component, ReadOptions); Sep 27 '17 at 9:26
  • 1
    I just wanted to make an update. I had some code issues previously, but to make everything clear after additional testing: both create, update and save return tcmid. Sep 28 '17 at 12:53
  • 1
    Thanks for the update, I was just about to go test it myself, as I was really sure this would work :)
    – Nuno Linhares
    Sep 28 '17 at 13:23

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.