How to get the id of a Tridion element after creation using the main service

I am creating a new item using the underlying service in this post . However, the URI of the newly created tcm element is: 0-0-0 instead of the actual TCM URI. The Title property is correct (and not a new component), but the WebDav path returns "New component".

What is the best way to get the URI of my newly created item?

client.Create(newComponent, null); string newItemUri = newComponent.Id; // returns tcm:0-0-0 string webDavUrl = newComponent.LocationInfo.WebDavUrl; // returns New%20Component string title = newComponent.Title; // correct 
+4
source share
2 answers

The second parameter of the Create method is ReadOptions. They are used to indicate how the item will be read. In your example, you are set to null, that is, you will not read it. What you need to do is set ReadOptions and set the reading of the element to a variable, for example:

 newComponent = (ComponentData) client.Create(newComponent, new ReadOptions()); 
+4
source

Check out Ryan's code at http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011 . It uses client.Save to retrieve a stored component from which it can access the ID.

+4
source

Source: https://habr.com/ru/post/1400202/


All Articles