I'M trying to solve this question, but it's not working, what am I doing wrong? I Have the following situation, I need that when the date_start field is searched in the Google data panel, it calls a URL, if the field is not in the panel call call another URL, follows the sample code, I am unable to execute the conditional hasDate out of the return function, could someone clarify this question? The first conditional within the function works normal, but the second outside is not entering the IF, only in the else!
var hasDate = false
Logger.log(hasDate);
var hasDate2 = request.fields.forEach(function(field){
var fieldName = field.name;
Logger.log(fieldName);
//Add time increment if date is one of the fields
if (fieldName == 'date_start' || fieldName == 'date_stop') {
hasDate = true;
Logger.log('Entrou no if');
} else {
hasDate = false;
Logger.log('Entrou no else');
}
for (var i = 0; i < faceBookDataSchema.length; i++){
if(faceBookDataSchema[i].name === field.name){
dataSchema.push(faceBookDataSchema[i]);
break;
}
}
});
if (hasDate) {
//requestOptions['time_increment'] = 1
Logger.log('Entrou if data!')
} else {
//requestOptions['time_increment'] = 'monthly'
Logger.log('Entrou else data!')
}
[19-03-19 11:23:18:008 BRT] Logger.log([false, []]) [0 seconds]
[19-03-19 11:23:18:009 BRT] Logger.log([false, []]) [0 seconds]
[19-03-19 11:23:18:009 BRT] Logger.log([account_currency, []]) [0 seconds]
[19-03-19 11:23:18:010 BRT] Logger.log([Entrou no else, []]) [0 seconds]
[19-03-19 11:23:18:010 BRT] Logger.log([date_start, []]) [0 seconds]
[19-03-19 11:23:18:011 BRT] Logger.log([Entrou no if, []]) [0 seconds]
[19-03-19 11:23:18:011 BRT] Logger.log([reach, []]) [0 seconds]
[19-03-19 11:23:18:012 BRT] Logger.log([Entrou no else, []]) [0 seconds]
[19-03-19 11:23:18:012 BRT] Logger.log([Entrou else data!, []]) [0 seconds]