Having trouble digging certain Publication Target elements out using C# I want to get the following:
- Allowed Publications
- Allowed Target Types
- Minimal Approval Status
I was able to get most everything else. Here is my code so far:
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHaving trouble digging certain Publication Target elements out using C# I want to get the following:
I was able to get most everything else. Here is my code so far:
All lists in returned from Tridion are partially loaded, ie. not all of the properties will be returned. This is done to reduce load on both database and application server and also to reduce the traffic size. Depending upon the filter class you are using you can set some additional columns to be preloaded, in addition to all filter classes having BaseColumns
which works with a limited set of properties. So, you have to use the list and then to retrieve everything of that item you will have to do another read operation of the item itself as @eric mentions.
foreach (PublicationTargetData t in targets)
{
PublicationTargetData target = (PublicationTargetData) client.Read(t.Id, new ReadOptions());
// You should be able to access all the properties here, however keep in mind any references you have to other Tridion objects will be links with Id and Title for eg. Publication, Target Types and Approval Stats
}
You can try this:
PublicationTargetData publicationTarget = (PublicationTargetData)channel.Read("[PublicationTargetId]", new ReadOptions());
IEnumerable<PublicationData> publications = publicationTarget.Publications.Select(s => (PublicationData)channel.Read(s.IdRef, new ReadOptions()));
IEnumerable<TargetTypeData> targetTypes = publicationTarget.TargetTypes.Select(s => (TargetTypeData)channel.Read(s.IdRef, new ReadOptions()));
ApprovalStatusData approvalStatus = (ApprovalStatusData)channel.Read(publicationTarget.MinApprovalStatus.IdRef, new ReadOptions());
This code will retrieve the actual Tridion objects. The CoreServices API will give you LinkTo[TridionObjectType] references instead of direct references to Tridion objects like the TOM .Net API because of performance reasons, remember that the CoreServices is a SOAP web service that needs to send information in a distributed environment and reducing the messages sizes is critical.
Having said that, in case you really need access to the actual Tridion object you can always use the IdRef property available in all the LinkTo[TridionObjectType] to retrieve the object. For instance for a Publication you will have a LinkToPublicationData
object.
IEnumerable<LinkToPublicationData> links = publicationTarget.Publications;
You can iterate though it to convert them into actual PublicationData
objects.
IEnumerable<PublicationData> publications = links.Select(s => (PublicationData)channel.Read(s.IdRef, new ReadOptions());
I hope this helps.