7

I have a need to bypass component workflow on the translated content. To achieve this i have planned to subscribe Save event at TransactionCommitted phase and then force finish the workflow activity.

I don't see i can able to capture this every time when i deploy dll with same code.

Note: We can't capture CheckInEvent in this case as component is getting into Tridion component workflow before that.

private void OnComponentSave(Component component, SaveEventArgs args, EventPhases phases)
        {
            try
            {
                //Please don't change the order of below condition as it is required to identify component has all properties loaded, and it is in workflow.
                if (!component.LoadState.Equals(LoadState.NotLoaded) && component.LockType.HasFlag(LockType.InWorkflow) && component.CurrentActivity != null)
                {
                    var currentActivity = component.CurrentActivity;

                    foreach (var performer in currentActivity.Performers)
                    {
                        if (WorkflowBypassingUsers.Contains(performer.Title.ToLower()))
                        {
                            var wfProcess = new ProcessInstance(currentActivity.Process.Id, component.Session);
                            ApprovalStatus status = new ApprovalStatus(new TcmUri(LiveApprovalStatusTcmUri), currentActivity.Process.Session);
                            _ = wfProcess.ForceFinish(status);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write("[XXX.EventSystem.WorkflowBypasser.OnComponentSave]: ", "Exception Message:" + ex.Message, LoggingCategory.General);
                throw new Exception(ex.Message);
            }
        }

Version: SDL Web 8.5

3 Answers 3

9

You can try the below events related to Workflow:

1.Event for Workflow process starts

EventSystem.Subscribe<ProcessInstance, StartWorkflowEventArgs>(OnProcessInstanceStart, EventPhases.Initiated);

2.Event for Workflow activity starts

 EventSystem.Subscribe<ActivityInstance, StartActivityEventArgs>(OnActivityInstanceStart, EventPhases.Initiated);

Also, usually the translated content publication is different from the source content publication. You can try disabling the workflow on the translated content publication if you don't have any specific requirements for workflow at the translated level.

1
  • Thank you Saurabh, TransactionCommitted phase of ProcessInstance suites my requirement. I have posted my working code as answer. Commented Sep 24, 2019 at 22:51
6

Looks like you may be using the wrong event? I don't know which event it is neither, so what I'd probably do is write a small event system that triggers on every event and logs enough details for me to be able to identify the one triggered by translation manager.

Something along the lines of this Example on Github

1
  • I can able to identify the event trigged by TM in this case with the help of your code. It is Save event - TransactionCommitted phase. I am not able to get debug event logs when it works. Commented Sep 11, 2019 at 2:25
0

Here is the solution that is working finally.

private const string TMKey = "TranslationManager";

private void Subscribe()
        {
            //Capture the WorkFlow process creation event after TM retrieves the component and workflow started on a returned component.
            this.EventSystem.Subscribe<ProcessInstance, StartWorkflowEventArgs>(OnProcessInstanceCommitted, EventPhases.TransactionCommitted);
        }`

private void OnProcessInstanceCommitted(ProcessInstance process, StartWorkflowEventArgs args, EventPhases phases)
        {
            try
            {
                //Check if the workflow triggered as part of a Save event triggered by Translation Manager, others we can skip.
                if (process?.Session?.ContextData?.ContainsKey(TMKey) != true)
                {
                    return;
                }
                if (process.Session.AccessToken != null && WorkflowBypassingUsers.Contains(process.Session.AccessToken.Title.ToLower()))
                {
                    ApprovalStatus status = new ApprovalStatus(new TcmUri(LiveApprovalStatusTcmUri), process.Session);
                    _ = process.ForceFinish(status);
                }
            }
            catch (Exception ex)
            {
               //Handle your exception
            }
        }

Your Answer

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

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