This will be a short post about why the method above is tricky. As its name says
ExecuteWorkflowCommandIfAvailable, but what “available” means in this context?
It means it checks if the user has rigths to execute the given workflow command even if you use
SecurityDisabler, because Sitecore uses
SecurityEnabler inside this method.
So the following code wont work if you are using it from out of Sitecore Context (e.g. a processor) because the current user is
sitecore\Anonymous in that case.
So instead of using
SecurityDisabler what you can do in this case? Use UserSwitcher instead but be careful with this, read about it first. It is not a good practice in all cases.
If you don’t want to create a specific real user in Sitecore you can use virtual user which is maybe more clean, because you don’t need to setup a password and roles in Sitecore but you can create this temporary user in your processor.
I did not know that you can omit
SecurityEnabler, but good to know for the future.