Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Tridion item ID after created using Core Service

Tags:

tridion

I am creating a new item using the Core Service in this post. However, the URI of the newly created item is tcm:0-0-0 instead of the actual TCM URI. the Title property is correct (and not New Component) but the WebDav path returns 'New Component' while .

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
like image 346
robrtc Avatar asked Feb 21 '23 05:02

robrtc


2 Answers

Second parameter of Create method are ReadOptions. They are used to specify how the item will be read back. In your example you have it set to null, meaning you will not read it back. What you should do is set ReadOptions and assign item read back to a variable, like this:

newComponent = (ComponentData) client.Create(newComponent, new ReadOptions());
like image 150
Andrey Marchuk Avatar answered Apr 27 '23 14:04

Andrey Marchuk


Check out Ryan's code at http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011. He uses client.Save to get the saved Component, from which he's able to access the ID.

like image 31
Jeremy Grand-Scrutton Avatar answered Apr 27 '23 14:04

Jeremy Grand-Scrutton