Transform For Loop Issue

Any ideas why my iterator isnt picking up in my concat function? The iterator i is indeed updating with each pass of the for but not in the concat.

image

workids should be
const workids = []

Instead of concat in the loop use
workids.push(stuff_youre_iterating_over);

Thanks Scott, but I need the results as a string so I can use it in another HTTP call. Either case the iterator still didn't update in the write statements.

Remove the second param (comma) in the push.
What should the formatting be for the http call?

Same thing. The iterator I doesn't update during write, but if put I into console it would show as incrementing as expected.

API call should be formatted like this, this transform is for the ids param of the call.
GET https://dev.azure.com/fabrikam/_apis/wit/workitems?**ids=297,299,300**&api-version=7.0

tried this to using the array and then return a .join() but the i inside .push() isn't iterating as expected, resulting in the same record being added to the array

var workids = [];
for (var i = 0; i < GetWorkItemsByUserName.data.length; i++) {
workids.push(GetWorkItemsByUserName.data[i].id);
}
return workids.join(',');

output is repeating [i] = 0 in the array

const dataRetreived = [1,2,3,4,5,6,7,8]; // this is your GetWorkItems data
const workids = [];
for(i=0;i< dataRetreived.length; i++){
  workids.push(dataRetreived[i]);
}
return "http://testurl.com?ids=" + _.toString(workids).replace(/\"/g, "")

Thanks for you help! Taking the static value approach I was able to work through the source data 'dataretrieved' and was able to back into the data I needed.

Thanks for the assist!!!

var workids = [];
var data = {{formatDataAsObject(GetWorkItemsByUserName.data).id}}

for (var i = 0; i < data.length; i++) {
workids.push(data[i]);
}
return workids.join(',');

1 Like