VMware Cloud Community
LaxmiRagi
Enthusiast
Enthusiast
Jump to solution

How to retrieve next run date of scheduled workflow using script

Hi There,

I am trying to find the API which will give the next run date, but i don't see any method in vRO.

I need to use that method in the script. so can anyone help me how to fetch it using script.

Thank you,

Laxmi

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Currently, the next run date of a scheduled workflow is not exposed in scripting.

View solution in original post

Reply
0 Kudos
5 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Currently, the next run date of a scheduled workflow is not exposed in scripting.

Reply
0 Kudos
LaxmiRagi
Enthusiast
Enthusiast
Jump to solution

Hi Ilian Iliev,

Thanks for the response, we cannot also retrieve last run also right ?

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Not directly, but there is a property that returns all runs, so you can sort/iterate over them and find the one with the most recent end date.

Reply
0 Kudos
LaxmiRagi
Enthusiast
Enthusiast
Jump to solution

Hi Ilian Iliev,

I have tried like below:

From Task object i will get executions

executions = task.executions //returns Array of WorkflowToken

lastexecution = execution[execution.length-1] //i will get last execution

wftokens = Server.findAllForType("WorkflowToken");

for each(token in wftokens){

    if (token.id === lastexecution['id']){

        lastrundate =  token.endDate

   }

}

System.log("Last rundate "+lastrundate)

Correct me if i am doing wrong.

Thank you,

Laxmi

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

The middle of this scripting code (lines 4-9) is not needed. You already have the value in variable lastexecution (line 2) so there is no need to iterate over all available tokens to search for it again.

The problem is that the array with executions on line 1 is not guaranteed to be ordered. That is, when you get its last element on line 2, there is no guarantee that the last element of the array will be the most recent execution of this scheduled workflow. So you need to:

1) either sort the executions array by end date property, and then get the last element

2) or iterate over the executions array, keeping track of which element has the most recent end date

Reply
0 Kudos