The issue I am encountering is that is that when I loop through array with "For" method, it always returns the last element of the array and it send the jobs to next outgoing flow with the last element of the array in all jobs
Let's for example say I have an array of ["Url1", "Url2","Url3"] , Switch sends 3 jobs and all of them carry privatedata of "Url3" while I want 3 jobs and each of them have a privatedata if url1 for 1st, url2 for 2nd and url3 for 3rd.
I tried different ways by adding index to the loop so the index will increase with every loop but I still get same result .
Below is one of the codes that that I tried
async function jobArrived(s,flowElement,job){
let links= await parseXPathAsString("file","/JSON/array/urls",job);
let cleanURLs= links.match(/\bhttps?:\/\/\S+/gi);
for(let i = 0; cleanURLs.length > i; i++) {
if (cleanURLs.indexOf('dropbox') != -1){
cleanURLs = cleanURLs.replace('dl=0', 'dl=1');
}
await job.setPrivateData("Link",cleanURLs);
await job.sendToSingle(job.get());
}
}
Any idea how to achieve looping through the Urls in the array and send amount of job based on how many urls exists in the array and each job MUST carry one url out of the array and have it as privatedata?
Thank you