We have a workflow enabled at schema level, and the moment new component is being created the workflow locks the component for the further approval tasks described in the workflow.
As we also need the locked component to be added on the page, which we can’t do on the minor version of the component, so we have written the following code to increment the component version by 1:
OnSaveEvent(EventPhases.Processed) of Component – we perform the following logic:
var processInstance = new ProcessInstance(subject.CurrentActivity.Process.Id, session);
var newSubject = new Component(subject.Id.GetVersionlessUri(), subject.Session);
The entire logic works fine when anyone creates a new component in Content Manager and the component gets locked by the workflow again after save operation.
However, when any new component is being imported using the content porter the code gives the below error:
Error Tridion.ContentManager.ItemDoesNotExistException: The item tcm:6-205283-16-v0 does not exist.
The API says, “All the Subjects of the related Work Items will be checked-in after a force finish”, so ideally the Content Porter should get the major version then why am I getting the error for minor version?
To differentiate the component creation from Content Porter vs Manual, I already tried to put a check if (subject.Session.ContextData.ContainsKey(TcmApplicationId.ImportExportService))
and execute the above code until force finish, as I don’t want the component to be locked by the Work Flow again, but still no luck. Can someone provide any clue what else we can try?