8

I'm using a custom event handler to generate an email when the status of Translation Jobs changes to InTranslation and Completed.

EventSystem.SubscribeAsync<ITranslationJob, ITranslationJobStateChangeEventArgs>(OnTranslationJobStateChange, EventPhases.Initiated, EventSubscriptionOrder.Early);

When the status is InTranslation I'm able to access the AddedItems property and include TCM & Title of the items from the translation job in my email. Usually bundles are sent to translation so its the bundle TCM & Title.

When the status is Completed, the AddedItems property is empty and I use TmsTranslationJobs.TargetItems to try and generate a list of it TCMs & titles of items that gave completed translated.

var targets = translationJob.TmsTranslationJobs.SelectMany(t => t.TargetItems);

If a bundle was sent originally, TmsTranslationJobs.TargetItems is actually the Component TCMs inside the bundle.

For some reason the API for TargetItems only contains the TCM (via the SourceUri property) of the Components inside a bundle, not titles.

enter image description here

I thought I could use this TCM to load the Component via the TOM.NET API and get its title but the TOM.NET API requires a Session object to be passed to every Component constructor but I'm not sure how to construct that Session object - as I haven't subscribed to a Content Manager object I have no access to a Session?

I see in the Session class it can be instantiated with a username:

var s = new Session(string userName); 

Is it safe to get a Session this way?

Cheers

  • Have you considered getting the title from the tcm Id using the Core Services API instead of the TOM API? You could just create a .NET Web method that will create the CoreService instance and return the title of the component TCMID you pass to it. – Headoo Mar 8 '18 at 10:42
  • 5
    I had, but it seems unnecessary to use the Core Service from within the context of an event handler. – Neil Mar 8 '18 at 11:50
7

There are two things you can do.

First

If it is sufficient or preferable for you to get AddedItems during complete event

They are available but not loaded.

Use ITranslationJob.LoadState property to see what data loaded in translation job

And then if AddedItems is not loaded

Use ITranslationJob.LoadDetails (TranslationJobLoadFilters.AddedItems) to load them.

Second

You can get always to TOM.NET Session by casting subject of event (e.g ITranslationJob or ITranslationConfiguration) to Tridion.ContentManager.IdentifiableObject and get current session from Session property.

Good luck

  • 1
    Great answer Yuri - many thanks. For our purposes I opted for the LoadState/LoadDetails approach. – Neil Mar 8 '18 at 16:52
3

I've read somewhere (on multiple occasions) that when in TOM.NET you should never initiate the Session object on your own, rather you should reuse the existing one. For example in Templating this is done with the engine.GetSession(), in Event handlers the subject of the event has a Session property, etc.

But looking at the Translation Manger API I see no way on how to acquire a "regular" session. Instead, it's the other way around where the session is used to create an ITmSession. (Do note that I'm not 100% certain of this, I could be mistaken, haven't worked with the Translation API that much).

Having all this said, I must also mention that I have seen Session objects initiated "by hand" and the code did work.

So to summarize, you can initiate the Session, but if there is another way, you should definitely take that route. Initiating the Session by hand is not recommended.

  • 2
    See my response on how to get to session in TM event handler (Just FYI for future) – Yuri Bondarchuk Mar 8 '18 at 16:21

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.