Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Scripts - Dynamic Variables - ifElse conditional statement

    Posted 08-25-2025 11:50
    I'm working on a script that receives multiple collections (lists) as input. Within the flow, a data action is triggered based on the ANI of the call. This data action returns arrays containing strings, numbers, and boolean values.
     
    However, since the scripter does not support passing decimal and boolean lists directly, I've created two additional string lists and convert the decimal and boolean arrays into string format.
    Additionally, the script includes a manual search capability that does allow assigning results directly to decimal and boolean lists.
     
    The issue arises when I attempt to assign the selected value to a dynamic variable. Here's the ifElse statement I'm currently using:
    ifElse(
      equal({{preformedSearch}}, true),
      getIndexValue({{colExtension}}, {{selectedRecordIndex}}),
      number(getIndexValue({{colExtentsionString}}, {{selectedRecordIndex}}))
    )
     
    Regardless of whether I perform a manual search or use the values passed into the script, I consistently receive a NaN for the extension.
    Can anyone spot what might be wrong with this ifElse statement or suggest a better approach for assigning the dynamic number variable?
    Thanks in advance!

    #Scripts

    ------------------------------
    Mark Mathis
    ------------------------------


  • 2.  RE: Scripts - Dynamic Variables - ifElse conditional statement
    Best Answer

    Posted 08-25-2025 14:53

    Just to let everyone kno, I figured out my issue, blasted parenthesis got me again



    ------------------------------
    Mark Mathis
    ------------------------------



  • 3.  RE: Scripts - Dynamic Variables - ifElse conditional statement

    Posted 18 days ago
    Edited by Matheus Mendonca 18 days ago
    Já me vi algumas vezes exatamente nessa situação 😄. Você passa um bom tempo revisando a lógica, os tipos das variáveis, as conversões e os dados recebidos, e no final descobre que o problema estava em um parêntese.
     
    Trabalhando com Scripts no Genesys Cloud, principalmente quando começamos a combinar variáveis dinâmicas, listas, conversões de tipo e funções como ifElse() e getIndexValue(), esses pequenos detalhes de sintaxe podem ser bem difíceis de identificar.
     
    Também achei interessante a sua abordagem de utilizar listas auxiliares em string para contornar as limitações com listas decimais e booleanas. É uma solução pragmática, principalmente quando precisamos receber os dados do fluxo e ainda manter flexibilidade dentro do Script.
     
    Obrigado por voltar ao tópico e compartilhar a causa. Saber que era a expressão,e não necessariamente a estrutura das listas ou a conversão,provavelmente vai poupar bastante tempo de quem encontrar o mesmo NaN no futuro.
    _________________________________________________________________________________________________________________________________________
    I've found myself in exactly this situation a few times 😄. You spend a lot of time reviewing the logic, variable types, conversions, and incoming data, only to discover that the problem was a parenthesis.
     
    When working with Genesys Cloud Scripts, especially when combining dynamic variables, collections, type conversions, and functions such as ifElse() and getIndexValue(), these small syntax details can be surprisingly difficult to spot.
     
    I also liked your approach of using auxiliary string collections to work around the limitations with decimal and boolean collections. It's a pragmatic solution, especially when you need to receive the data from the flow while still keeping some flexibility inside the Script.
     
    Thanks for coming back and sharing the root cause. Knowing that it was the expression, rather than the collection structure or the conversion itself, will probably save some time for anyone who runs into the same NaN behavior in the future.



    ------------------------------
    Matheus Mendonca
    ------------------------------



  • 4.  RE: Scripts - Dynamic Variables - ifElse conditional statement

    Posted 15 days ago

    It looks like your ifElse statement is syntactically correct, and the functions you are using, such as ifElse, equal, getIndexValue, and number, are all valid for dynamic variables in Genesys Cloud scripts. However, the fact that you are consistently getting NaN, which stands for Not a Number, in both branches points to a few common pitfalls with how dynamic variables handle data types, lists, and indexes, and there are several things to check before concluding that the logic itself is wrong.

    The most likely culprit is a simple typo or a data type mismatch, and your statement uses {{colExtension}} in the true branch and {{colExtentsionString}} in the false branch, so you should notice the spelling difference on the word "Extension" between these two variable names. If one of these variable names is incorrect, the function will not be able to find the list, which can result in NaN, so it is critical to double-check that these variable names exactly match the names of your dynamic variables, including capitalization. It is also worth remembering that in dynamic variables, expressions are evaluated in order, and the last value evaluated is what gets assigned to the variable. Additionally, you should confirm that your string lists actually contain values that can be converted to numbers, because you mentioned that you are converting decimal and boolean arrays into string format, and if any of those string values contain non-numeric characters, such as a currency symbol or a boolean value like "true" or "false", the number() function will fail to convert them and will return NaN.

    If the variable names are correct, the next most likely issue is the selectedRecordIndex, because the getIndexValue function returns the value at the position specified by the index number, and in Genesys Cloud, list indexes are zero-based, meaning the first item is at index 0. If your selectedRecordIndex is 0, it will correctly get the first item, but if your logic expects a 1-based index where the first item is 1, you will be off by one. More importantly, according to the documentation, the getIndexValue function returns an error if the index number is equal to or larger than the size of the list, which means if your list has three items and selectedRecordIndex is 3, referring to a fourth item that does not exist, the function will error and return NaN.

    Another point to consider is the data type conversion after getIndexValue, because the number() function is generally used to convert a string representation of a number into an actual number data type, but if getIndexValue on {{colExtension}} already returns a number, then applying number() to it might not be necessary and could occasionally cause issues, although it usually works fine. The real risk is in the false branch where you have number(getIndexValue({{colExtentsionString}}, {{selectedRecordIndex}})), because if the value returned from getIndexValue cannot be cleanly converted, for example if it contains a comma or a decimal point that is not handled correctly, the number() function will return NaN. There is also a known issue where the string() function can transform numbers with more than five digits into a decimal format with an "e+" notation, which might cause problems, but the number() function itself expects a clean numeric string.

    To address this in a more robust way, you can start by adding some validation before your ifElse statement. You could create a couple of simple dynamic number variables to test if you can get a value directly, for instance by creating a dynamic number variable called testNumber with the expression number(getIndexValue({{colExtentsionString}}, 0)) to test if the first item in your string list can be converted to a number, and creating another dynamic number variable called testIndex with the expression {{selectedRecordIndex}} to confirm that this variable is indeed a number and not a string. In your false branch, you could also try just getIndexValue({{colExtentsionString}}, {{selectedRecordIndex}}) and assign it directly to a dynamic string variable to see what the raw value is, which can help you spot unexpected characters, and then you can decide if the number() conversion is truly needed, because if you are just using this value for display or comparison, you may not need to convert it at all. In the true branch, you are referencing {{colExtension}} directly, and if this is the list you are populating from a manual search, you should ensure that you are correctly populating it with number values, since the script editor does allow assigning results directly to decimal and boolean lists, so the values in {{colExtension}} should already be numbers. Finally, do not forget to check for any stray parentheses, because a misplaced parenthesis in a long expression can sometimes lead to unexpected results, and it has even been reported as the cause of a similar issue in the community.

    By isolating each piece of the expression and checking the raw data, you should be able to identify exactly where the NaN is coming from and adjust your approach accordingly.



    ------------------------------
    Camila Meneghini
    ------------------------------