Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
...
let responseMessage: string = '';
const statusOptions = [ 'All', 'Running', 'Failed', 'Cancelled', 'Succeeded' ];
const NO_FILTER = 0;
var runsList = {
runs: []
};
let runsCount = 0;
let nextLink: string = `https://management.azure.com/providers/Microsoft.ProcessSimple/scopes/admin/environments/${environment}/flows/${flow}/runs?api-version=2016-11-01`;
if(statusOption != statusOptions[NO_FILTER])
nextLink += `&$filter=Status%20eq%20%27${statusOption.toLowerCase()}%27`;
try {
while(nextLink && runsCount <= RUNS_LIMIT) {
await getHttp(nextLink,
req.headers['authorization'])
.then(runs => {
if(!runs || !runs.value)
throw Error('No runs found - the response is unexpected');
const items = (periodOption != periodOptions[NO_FILTER]) ?
runs.value.filter( (item) => new Date(item.properties.startTime) >= dateFrom && new Date(item.properties.startTime) <= dateTo) :
runs.value;
items.forEach(element => {
runsList.runs.push(
{
'id': element.id,
'name': element.name,
'type': element.type,
'properties': element.properties
}
)
});
runsCount += items.length;
nextLink = runs.nextLink;
});
}
responseMessage = JSON.stringify(runsList);
context.log(`Total runs found: ${runsList.runs.length}`);
}
catch ( err ) {
responseMessage = `Error: ${err}`;
}
...
@amirmsai
Copy link

amirmsai commented Aug 11, 2021

Hi Andrew,
what type of scope do you used ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment