Filter by field searched in dash Google Data Studio, does not work?

ぐ巨炮叔叔 提交于 2019-12-13 03:18:25

问题


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]

来源:https://stackoverflow.com/questions/55243367/filter-by-field-searched-in-dash-google-data-studio-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!