- I am doing some external operations if they get failed I have to mark a 'ScheduledForPublish' item to 'Failed' in publishing queue. I don't want to delete the item from Publishing queue. how can I do it with Tridion Core service.
- I have an Item 'ScheduledForPublish'. To force the publish there is 'ExecuteTask' option in GUI. Is there anything like that in core service API?
You cannot set a publish action to failed yourself, but you can make sure that something in the rendering (template code) or deployment process fails, which will mark the transaction as failed.
You mention a scheduled publish item and that you are doing some external operations, what is triggering these external operations? If you trigger them through the event system on the publish action, then that is something you might also want to use for raising the error which will fail the publish transaction.
If your external process is completely separate from the publish transaction, then you cannot have that interact with the publish transaction (other than deleting it from the queue while it hasn't been started yet). But you could consider implementing something in the template code which would check your external process and see if it needs to fail this transaction. Not an optimal process, but that is about the maximum you can get out of it (given that you want to fail a scheduled transaction which hasn't even started yet).
As for your #2 question, try changing the scheduled date to the current date and time, that should make it execute directly (not sure if that can be done through the core service, but worth a shot, I'm pretty sure the UI also uses something like that for the execute task option).