I have the following code :
for(var index in workload.elements) { var arr = []; var resourceIdentifiers = {}; var elementinfo = {}; var metadataModified = {};
elementinfo = workload.elements[index];
arr[index] = workload.elements[index].uri;
if(workload.elements[index].parameters.imageUri)
{
arr.push(workload.elements[index].parameters.imageUri);
}
resourceIdentifiers = arr.join(',');
console.log('uri' + resourceIdentifiers);
// connects with mysql and fetch data
mysql.elementlevelpricing(resourceIdentifiers, function(result){
elementlevelpricingSummary = JSON.stringify(result,null,2);
console.log('resultin' + elementlevelpricingSummary);
});
console.log('resultout' + JSON.stringify(elementlevelpricingSummary,null,2))
}
The value of the variable elementlevelpricingSummary becomes empty as {} when accessed outside the called function mysql.elementlevelpricing().
The function passed to mysql.elementlevelpricing is an asynchronous callback, so it is actually running after the console.log line below it. You'll want to do anything you need the data for in the callback itself.