Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Displaying array as table in script

    Posted 29 days ago

    Hi!

    I'm struggling to understand how do dynamically display table in agent script based on an array variable in architect. As i understand we could use markdown component in script, but I can not find a way to construct a variable in a way that it would actually display as a table. Has anyone experience and some examples how that coud be obtained.

    Thanks in advance


    #Scripts

    ------------------------------
    Armands Bunkovskis
    Adventus Solutions Sia
    ------------------------------


  • 2.  RE: Displaying array as table in script

    Posted 28 days ago
    Edited by Luiz Rosa 28 days ago

    Hi Armands Bunkovskis

    I had this same issue before. In my case, the list had a fixed maximum size, and its length was passed through the flow, so I could handle it. I created several screens in the script and, depending on the list size, I built the table in Markdown through actions and displayed the corresponding screen.
    At that time, I also tried to create a Node.js code in a Data Action to generate the table dynamically, but I couldn’t make the script interpret the \n correctly to render the table. Not sure if that’s possible today.
    Hope this helps, and if anyone has faced something similar, please share your experience.



    ------------------------------
    Luiz Rosa
    Full stack developer
    ------------------------------



  • 3.  RE: Displaying array as table in script

    Posted 28 days ago
    Thanks.
    Yes, I'm having the same issue with not able to find yet a way to correctly interpret the \n in markdown tables

    Armands







  • 4.  RE: Displaying array as table in script

    Posted 27 days ago

    Uma abordagem alternativa - embora mais manual - seria iterar sobre o array diretamente no Architect, armazenando os elementos em variáveis individuais. Posteriormente, essas variáveis poderiam ser referenciadas no Agent Script como dados do participante, permitindo a construção de uma tabela dinâmica com base no volume do array.

    Essa solução não é escalável para arrays grandes, mas pode funcionar como uma estratégia paliativa em cenários onde o número de elementos é previsível ou limitado. Vale lembrar que o componente Markdown no Agent Script tem limitações na renderização dinâmica, especialmente quando se trata de estruturas como tabelas baseadas em variáveis compostas.

    An alternative - albeit more manual - approach would be to iterate through the array within Architect and store each element in individual participant data variables. These variables could then be referenced in the Agent Script to construct a table-like structure.
    While this method doesn't fully solve the dynamic rendering challenge, it can serve as a workaround in scenarios where the array size is predictable or limited. Keep in mind that the Markdown component in Agent Scripts has limitations when it comes to rendering dynamic tables based on variable arrays.



    ------------------------------
    Fernando Sotto dos Santos
    Consultor
    ------------------------------



  • 5.  RE: Displaying array as table in script

    Posted 24 days ago

    Hi, regarding array size - you can get it inside the script using a numeric dynamic variable with the expression length( {{myListVariable}} )



    ------------------------------
    Christian Karpp
    Principal PS Consultant
    ------------------------------



  • 6.  RE: Displaying array as table in script

    Posted 24 days ago
    Edited by Christian Karpp 24 days ago

    Hi,
    it works fine with the help of dynamic variables and some actions.

    The key is that "\n" in the expression of a Dynamic String Variable / Text Expression is interpreted fine when used as source for the Markdown.

    Ingredients:

    mdTableColumn1Rows, mdTableColumn2Rows: string list variables (input) with the entries for each column.

    mdTableFinal      : string variable, to hold the final Markdown.
    mdTableHeader  : dynamic string variable, expr. " | Name | Age | \n | --- | ---  | \n". 
    mdRowIndex      : numeric variable.

    A custom action which initializes building the Markdown table, could be triggered by a button, on page load...:

    The action mdAddRow is adding the rows from the input arrays:

    As last step, the action calls itself recursively. Wrapped in the if-statement, this stops when no more rows from the input array are left to be processed.
    NOTE: This works in general, but I don't know if recursion depth (= no. of records) has its limits...



    ------------------------------
    Christian Karpp
    Principal PS Consultant
    ------------------------------