VMware Aria Automation Orchestrator

 View Only

 How to re-run a Workflow with same parameters from javascript?

Cashi's profile image
Cashi posted Sep 12, 2024 05:29 AM

Hi,

starting a new Workflow in Javascript is no problem, but how to restart a given Token?
I get all wf runs with "Server.findAllForType("WorkflowToken")" and pick one out to restart with same input attributes but seems not so easy?

Thanks, Daniel

WhiteForEver's profile image
WhiteForEver

Hi,

Let's say you want to restart a workflow called "aaa". Please use the code below to do so. You can play with "b.state" to decide what the state of the workflow you want to restart should be before you restart it. The available states are: "completed", "running”, or "failed". The "b.getInputParameters()" will make sure the same inputs will be reused. If needed, you can add "b.getAttributes()" to reuse the attributes as well.

var bb = Server.findAllForType("WorkflowToken")
for each (b in bb) {
    if (b.currentWorkflow.name === "aaa" && b.state != "running") {
        b.currentWorkflow.execute(b.getInputParameters())
    }
}
antonioaraujo's profile image
antonioaraujo

Hi Colleagues,

I hope you are fine.

This is not a response for the main question, I would like to know if there is a faster solution to check if a specific workflow (workflow id) is running than the proposed by @WhiteForEver, thanks for that! 

I tried your solution and it works fine. However, if we have a lot of WorkflowTokens (executions) the time for checking will increase, right? the more workflow tokens the more iterations within the loop.

Best regards

Antonio

WhiteForEver's profile image
WhiteForEver

Hi, Daniel.

Your original question was "...how to restart a given Token?" + "...and pick one out to restart with same input attributes". You got an answer exactly to what you did ask for. Therefore, when you say "This is not a response for the main question", I am not sure what do you mean. Because in your comment to the provided answer you are asking totally different question: "I would like to know if there is a faster solution to check if a specific workflow (workflow id) is running". If you want to expend your original question, there is no a problem with that. But I am not sure saying "this is not a response for the main question" is a right thing to say.

Cashi's profile image
Cashi

Hi

i am fine and have exactly, what i needed. Thanks for that.
Its another user, that made the new question.

Greetings, Daniel

WhiteForEver's profile image
WhiteForEver

Got it ☺️. No problem.

antonioaraujo's profile image
antonioaraujo

Dear @Cashi and @WhiteForEver,

I hope you are fine.

Please excuse me for the misunderstanding. Your response was totally fine. I just wanted to say that my comment was not an answer for this question. I will create a new question.

Best regards

Antonio