I have written a plugin for SDL Translation Management Service which should add the UserData for the creator of the TranslationJob
to the resolved items:
public void TranslationJob_Resolved(object sender, ResolvedItemsEventArgs e)
{
// Create a duplicate IEnumerable to make modifications to the resolved items
List<ResolvedItem> resolvedItems = e.Items.ToList();
try
{
// Retrieve the translation job
TranslationJob translationJob = sender as TranslationJob;
if (translationJob != null)
{
// Retrieve the creator TcmUri
TcmUri creatorUri = translationJob.CreatorUri;
// Use the CoreService to retrieve the creator TcmItem
UserData userItem = CoreServiceFactory.Get<UserData>(creatorUri.ToString());
if (userItem != null)
{
Logger.Log("User Item found for: " + userItem.Title);
// Create a new tcmUri to set the publication to 0
TcmUri tcmUri = new TcmUri(creatorUri.ItemId, creatorUri.ItemType, 0, creatorUri.Version);
// Validate the user and create a TcmItem
TcmItem tcmItem = new TcmItem(tcmUri);
// Add the creator TcmItem to the translation job resolved items
ResolvedItem resolvedItem = new ResolvedItem(tcmItem, translationJob);
resolvedItems.Add(resolvedItem);
}
}
}
catch(Exception ex)
{
Logger.Log("Unexpected error: {0}", ex);
}
// Assign the modified IEnumerable
e.Items = resolvedItems;
}
An exception is thrown when trying to initialise a new ResolvedItem
object:
Tridion.TranslationManager.DomainModel.TcmClientException: Invalid context Publication specified in URI: tcm:115-19-65552. Expecting: 0. ---> System.ServiceModel.FaultException`1[Tridion.ContentManager.CoreService.Client.CoreServiceFault]: Invalid context Publication specified in URI: tcm:115-19-65552. Expecting: 0.
I am struggling to determine why the publication component of the TcmId is 115 despite me explicitly setting it to 0 for the tcmUri
.
Can anyone provide any guidance on why this is happening and how I can resolve it?