2

I have written a SDL Translation Manager plugin which invokes on onSave event of any Translate action performed on page or bundle. Once I perform the business logic I want to delete the job created and for that I am using the method TranslationJob.Delete(), which doesn't throw any error but also doesn't delete the job and I can still see the JOB title in the "Translation Jobs" console.

Let me know if I am missing anything, 1 possibility I could think of is that the previous operations are not yet committed and I am trying to delete the job which is not yet completed but if I am correct then how should I solve that?

Thanks

2
  • 1
    Please clarify the question a bit. TMS typically refers to translation management system (or maybe specifically SDL TMS). I assume you mean Tridion Translation Manager (TM) here, and it is not code running on a translation management system? The Core Service does not grant access to translation manager objects, so are you referring to an event handler written against the TM .NET API (a plugin)? And can you please let us know what status the job has in the translation job list before or after you call the method? Feb 22, 2016 at 18:03
  • Sorry, if my question was not clear, but yes you are right I am talking about SDL Translation Manager where I have written an event handler which gets invoked on save event. I am then scanning all the pages added in the translation job and process them as per the business reqt. and then trying to delete the job just created. The job status in Translation Jobs sections is showing the status as "Definition". Thanks
    – Yash
    Feb 22, 2016 at 22:26

2 Answers 2

2

The method signatures of the Translation Manager plugin's you'll likely use look like this

private void JobCreated(object sender, TranslationJobEventArgs e)
private void Job_Saving(object sender, EventArgs e)

For JobCreated, the TranslationJobEventArgs contains a property called TranslationJob which can be used

For Job_Saving the sender can be cast to a TranslationJob

Once you have a TranslationJob you would then call job.Delete();

The best method to call job.Delete(); is Job.Saved as shown below

public class DeleteJobTranslationManagerPlugin
{
   public DeleteJobTranslationManagerPlugin()
   {
      //Subscribe to Translation Manager events
      TranslationJobManager.TranslationJobCreated += TranslationJobManagerOnTranslationJobCreatedOrLoaded;
      TranslationJobManager.TranslationJobLoaded += TranslationJobManagerOnTranslationJobCreatedOrLoaded;
   }

   private void TranslationJobManagerOnTranslationJobCreatedOrLoaded(object sender, TranslationJobEventArgs translationJobEventArgs)
   {
      TranslationJob job = translationJobEventArgs.TranslationJob;
      job.Saved += Job_Saved;
   }

   private void Job_Saved(object sender, EventArgs e)
   {
      var job = (TranslationJob)sender;
      job.Delete();
   }
 }

There is no requirement for CoreService to delete a TranslationJob

1

It would probably have been better if the API would throw an InvalidOperationException when Delete is called from within an event handler.

As it is now, the outcome is "undefined", meaning the API is not designed to perform this operation and we do not have a "correct behavior" of the API in this case. Even if it had worked, I would not recommend calling Delete from an event handler - it makes it hard to get systems with multiple event handlers working (and remember Tridion use event handlers internally, so even if you only have one event handler in the implementation you can run into problems).

If you want to delete a job as it is being created silently (so without a user get an error message) you probably have to perform the delete after the event handler completes. You can do that by hooking into the current transaction scope - it can raise an event when the scope completes. Then you should safely be allowed to delete the job. Of course this means you run without transaction support in this part, so in case you run into an error, the job can remain on the system anyway.

In SDL Web 8 we hooked Translation Manager into the same event system as the core is using, so here you have access to raise events after transaction scope completion directly out of the box - but it is quit easy to do it manually in Tridion 2013.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.