'If the failing expression is known to be legally refer to something that's sometimes null or missing

i have this problem with netsuite in Line 406 with the comparation in values with a index items.

The following has evaluated to null or missing: ==> listadoItems[item?index-1]
[in template "template" at line 406, column 47]
---- Tip: It's the final [] step that caused this error, not those before it.
---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use
<#if myOptionalVar??>when-present<#else>when-missing</#if>.
(These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
---- FTL stack trace ("~" means nesting-related):
Failed at: #if (listadoItems[item?index - 1].cus...
[in template "template" at line 406, column 41
<#if (listadoItems[item?index+1]?? && item_index != 0)>
  
    <#if (listadoItems[item?index+1].custcol_3k_establecimientooculto != listadoItems[item?index].custcol_3k_establecimientooculto)>
      
        <#assign mostrarEstSiguiente = 1>
    </#if>
<#else>
    <#if item?is_last>
        <#if (listadoItems[item?index-1].custcol_3k_establecimientooculto?? != listadoItems[item?index].custcol_3k_establecimientooculto)>
            <tr>
                <td width="100%" background-color="#e3e3e3" colspan="3">${"Establecimiento: " + item.custcol_3k_establecimientooculto??}</td>
            </tr>
        </#if>
    </#if>
</#if>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source