Popup window does not show result of Arcade expression

523
5
Jump to solution
08-10-2017 04:43 PM
XanderBakker
Esri Esteemed Contributor

I have created a Web Map in ArcGIS Online containing polygons for solid waste collection and each polygon contains information of the days the truck collects in that zone and the time range wherein that happens. I thought it would be nice to create an Arcade expression that would show the next moment the truck passes in each area.

For some reason the result of the expression is not shown in the popup. The expression result appears blank for any selected polygon:

This should probably be caused by some error in the expression, but the weird thing is, that the test in the Arcade window does return a valid result:

I wrote some values to the console and in this case it used a polygon with frequency "WS" (Wednesday and Saturday = Miércoles y Sábado:(

So, why do I have a result for the test, but in the popup there is no result for the same polygon and attributes?

Below the setting for the popup window:

And the script I have so far:

// weekdays 0=DO, 1=LU, 2=MA, 3=MI, 4=JU, 5=VI, 6=SA 
var dias = {'LJ': [1, 4], 'MV': [2, 5], 'WS': [3, 6], 'LWV': [1, 3, 5], 'MJS': [2, 4, 6], 'LaS': [1, 2, 3, 4, 5, 6]};
var horas = {'3PM A 7PM': [15, 19], '6AM a 10AM': [6, 10], '8AM a 12M.': [8, 12], '9PM a 1AM':[21, 24]};

var ahora = Now();
var hoy = Weekday(ahora);
var hora = Hour(ahora);
Console('hoy:' + hoy);
Console('hora:' + hora);

Console('Freq:'+$feature.FRECUENCIA);
Console('horario:'+$feature.HORARIO);

var lst_dias = dias[$feature.FRECUENCIA];
Console('lst_dias:' + lst_dias);

var lst_hora_minmax = horas[Upper($feature.HORARIO)];
Console('lst_hora_minmax:' + lst_hora_minmax);

var test = IndexOf(lst_dias, hoy)
Console('test:' + test);

var resultado = 'Not Set';
if (test != -1) {
    Console('hoy en lista')
    resultado = 'pasó hoy:' + $feature.HORARIO;
    hora_max = lst_hora_minmax[1];
    if (hora < hora_max) {
        resultado = 'viene hoy: ' + $feature.HORARIO;
    }
} else {
    Console('hoy no en lista, buscar próximo día');
    // find next day
    var dia_min = lst_dias[0];
    Console('dia_min:' + dia_min);
    var i = 0;
    for (var a in lst_dias) {
        i++;
    }
    Console('i:'+i);
    var dia_max = lst_dias[i-1];
    Console('dia_max:' + dia_max);
    if (hoy < dia_min) {
        Console('hoy < dia_min');
        var dif_days = dia_min - hoy;
        var next_day = DateAdd(Today(), dif_days, 'days');
        
    } else if (hoy > dia_max) {
        Console('hoy > dia_max');
        var dif_days = dia_min + 7 - hoy;
        var next_day = DateAdd(Today(), dif_days, 'days');
    } else {
        // entre min y max, pilas hay más de un elemento
        Console('hoy entre min y max');
        var dif_days = dia_max - hoy;
        var next_day = DateAdd(Today(), dif_days, 'days');
    }
    Console(next_day);
    var mes = Month(next_day) + 1;
    resultado = Day(next_day) + "-" + mes + "-" + Year(next_day) + ' - ' + $feature.HORARIO;
}

return resultado;

 

It is still not finished, but it should give some result and I would expect that it would give me the same result as during the test in the Arcade expression editor.

Does anyone know what might be wrong with the expression or somewhere else?

CC: KGerrow-esristaff

https://community.esri.com/community/developers?sr=search&searchId=a4c7f5bd-4c33-4c15-864d-ff3a75503...

0 Kudos
1 Solution

Accepted Solutions
KellyGerrow
Esri Frequent Contributor

Hey Xander Bakker‌,

I take no credit for this answer as some others researched and found the answer, but I'm happy to report the solution. There is an issue with the editor that caused the error not to be recognized, when the script was failing. The development team is going to work on this.

The hora_max variable was missing a declaration. Please see the highlighted script below:

// weekdays 0=DO, 1=LU, 2=MA, 3=MI, 4=JU, 5=VI, 6=SA

var dias = {'LJ': [1, 4], 'MV': [2, 5], 'WS': [3, 6], 'LWV': [1, 3, 5], 'MJS': [2, 4, 6], 'LaS': [1, 2, 3, 4, 5, 6]};

var horas = {'3PM A 7PM': [15, 19], '6AM a 10AM': [6, 10], '8AM a 12M.': [8, 12], '9PM a 1AM':[21, 24]};

 

var ahora = Now();

var hoy = Weekday(ahora);

var hora = Hour(ahora);

 

var lst_dias = dias[Upper($feature.FRECUENCIA)];

 

var lst_hora_minmax = horas[Upper($feature.HORARIO)];

 

var test = IndexOf(lst_dias, hoy)

 

var resultado = 'Not Set';

if (test != -1) {

    Console('hoy en lista')

    resultado = 'pasó hoy:' + $feature.HORARIO;

    var hora_max = lst_hora_minmax[1];

    if (hora < hora_max) {

        resultado = 'viene hoy: ' + $feature.HORARIO;

    }

} else {

    // find next day

    var dia_min = lst_dias[0];

    var i = 0;

    for (var a in lst_dias) {

        i++;

    }

 

    var dia_max = lst_dias[i-1];

    console(i)

    if (hoy < dia_min) {

        var dif_days = dia_min - hoy;

        var next_day = DateAdd(Today(), dif_days, 'days');

       

    } else if (hoy > dia_max) {

        var dif_days = dia_min + 7 - hoy;

        var next_day = DateAdd(Today(), dif_days, 'days');

    } else {

        // entre min y max, pilas hay más de un elemento

        var dif_days = dia_max - hoy;

        var next_day = DateAdd(Today(), dif_days, 'days');

    }

    var mes = Month(next_day) + 1;

    resultado = Day(next_day) + "-" + mes + "-" + Year(next_day) + ' - ' + $feature.HORARIO;

}

 

return resultado;

 

Add the declaration, and let us know if it fixed the error.

-Kelly 

View solution in original post

5 Replies
KellyGerrow
Esri Frequent Contributor

Hey xander_bakker‌,

Are you able to share your web map that you are working with?

-Kelly

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Kelly Gerrow , 

I just shared the Web Map to the public. Here is the URL:

http://arcg.is/4yz81 

Thanks in advance!

Kind regards, Xander

0 Kudos
XanderBakker
Esri Esteemed Contributor

This is the URL to the hosted features service:

https://services3.arcgis.com/wPe5k6dJ32ybQjvP/arcgis/rest/services/RecoleccionEMVARIAS/FeatureServer 

The expression is applied to the third layer "Zonas Bloques"

0 Kudos
KellyGerrow
Esri Frequent Contributor

Hey Xander Bakker‌,

I take no credit for this answer as some others researched and found the answer, but I'm happy to report the solution. There is an issue with the editor that caused the error not to be recognized, when the script was failing. The development team is going to work on this.

The hora_max variable was missing a declaration. Please see the highlighted script below:

// weekdays 0=DO, 1=LU, 2=MA, 3=MI, 4=JU, 5=VI, 6=SA

var dias = {'LJ': [1, 4], 'MV': [2, 5], 'WS': [3, 6], 'LWV': [1, 3, 5], 'MJS': [2, 4, 6], 'LaS': [1, 2, 3, 4, 5, 6]};

var horas = {'3PM A 7PM': [15, 19], '6AM a 10AM': [6, 10], '8AM a 12M.': [8, 12], '9PM a 1AM':[21, 24]};

 

var ahora = Now();

var hoy = Weekday(ahora);

var hora = Hour(ahora);

 

var lst_dias = dias[Upper($feature.FRECUENCIA)];

 

var lst_hora_minmax = horas[Upper($feature.HORARIO)];

 

var test = IndexOf(lst_dias, hoy)

 

var resultado = 'Not Set';

if (test != -1) {

    Console('hoy en lista')

    resultado = 'pasó hoy:' + $feature.HORARIO;

    var hora_max = lst_hora_minmax[1];

    if (hora < hora_max) {

        resultado = 'viene hoy: ' + $feature.HORARIO;

    }

} else {

    // find next day

    var dia_min = lst_dias[0];

    var i = 0;

    for (var a in lst_dias) {

        i++;

    }

 

    var dia_max = lst_dias[i-1];

    console(i)

    if (hoy < dia_min) {

        var dif_days = dia_min - hoy;

        var next_day = DateAdd(Today(), dif_days, 'days');

       

    } else if (hoy > dia_max) {

        var dif_days = dia_min + 7 - hoy;

        var next_day = DateAdd(Today(), dif_days, 'days');

    } else {

        // entre min y max, pilas hay más de un elemento

        var dif_days = dia_max - hoy;

        var next_day = DateAdd(Today(), dif_days, 'days');

    }

    var mes = Month(next_day) + 1;

    resultado = Day(next_day) + "-" + mes + "-" + Year(next_day) + ' - ' + $feature.HORARIO;

}

 

return resultado;

 

Add the declaration, and let us know if it fixed the error.

-Kelly 

XanderBakker
Esri Esteemed Contributor

Hi Kelly Gerrow  thanks a lot and please pass my gratitude to those that solved the issue in my code!  

I will have to be more careful with those type of declarations. There are not required in Python where I spend most of my time scripting, so it will take some adjustment for me to get this right. 

0 Kudos