Skip to content

Instantly share code, notes, and snippets.

@chrismrgn
Last active March 7, 2016 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismrgn/955b34bf757d0f7ade6c to your computer and use it in GitHub Desktop.
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
[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