Last active
March 7, 2016 19:08
-
-
Save chrismrgn/955b34bf757d0f7ade6c to your computer and use it in GitHub Desktop.
Fast Forward item in SDL Tridion Events to ease Workflow and Adding Component to Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TcmExtension("Event System")] | |
public class EventSystem : TcmExtension | |
{ | |
public EventSystem() | |
{ | |
Subscribe(); | |
} | |
public void Subscribe() | |
{ | |
//Workflow Related Events | |
EventSystem.Subscribe<Component, SaveEventArgs>(ComponentSavedWorkflowEvent, EventPhases.Processed); | |
} | |
private void ComponentSavedWorkflowEvent(Component subject, SaveEventArgs e, EventPhases phase) | |
{ | |
if(subject.IsNew) | |
{ | |
if(subject.GetProcessDefinition() != null) | |
{ | |
//Get current instance & force finish version 0.x | |
var processInstance = new ProcessInstance(subject.CurrentActivity.Process.Id, subject.Session); | |
processInstance.ForceFinish(new ApprovalStatus(subject.Session)); | |
//Trigger save to send version 1.x into workflow | |
var newSubject = new Component(subject.Id.GetVersionlessUri(), subject.Session); | |
newSubject.CheckOut(); | |
newSubject.Save(true); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment