info:
  name: Elenco RS CSV (cognome nome)
  type: http
  seq: 14

http:
  method: POST
  url: "{{elixFormsApiUrl}}/eftl/process/v1"
  headers:
    - name: x-requested-with
      value: XMLHttpRequest
    - name: x-api-key
      value: "{{elixFormsWsAuthenticationToken}}"
    - name: x-ef-request-id
      value: "17144"
  body:
    type: json
    data: |-
      {
        "userDocument": "{{elixBase64EftlDocument}}", // see the pre-request script
        "userContext": {
          "lang": "IT"
        }
      }
  auth: inherit

runtime:
  scripts:
    - type: before-request
      code: |-
        const { prepareEftlDocument } = require("./elixFormsJs.js")
        // Copy-pasta your EFTL document below inside the template literals (`)
        prepareEftlDocument(String.raw`
        [EFTL][HEADER name="trimDocument" value="true" type="boolean" /]

        [VAR name="firstItem" type="number"][% firstItem = 0; %][/VAR]
        [VAR name="secondItem" type="number"][% secondItem = 1; %][/VAR]
        [VAR name="elencoResponsabiliCsv" type="string"][% elencoResponsabiliCsv = ""; %][/VAR]

        [VAR name="elencoResponsabili" type="string"][TRIM][TAG]GETVALUEBYTAG,PROPOSTA_CCT_ALTRI_RS,REQUEST,ID_OBJECT[/TAG][/TRIM][/VAR]
        [VAR name="elencoResponsabiliIterable" type="iterable"][SPLIT regex="\n" emptyIfBlank="true"][VALUE_OF varname="elencoResponsabili" /][/SPLIT][/VAR]
        [VAR name="elencoResponsabiliCount" type="number"][SIZE_OF varname="elencoResponsabiliIterable" /][/VAR]

        [VAR name="responsabileIdx" type="number"][% responsabileIdx = 0; %][/VAR]
        [WHILE threshold="99"]
        [CONDITION][% responsabileIdx < elencoResponsabiliCount %][/CONDITION]
        [DO]
          [VAR name="responsabileIterable" type="iterable"][SPLIT regex=", CF: " emptyIfBlank="true"][TRIM][VALUE_OF varname="elencoResponsabiliIterable" index="responsabileIdx" /][/TRIM][/SPLIT][/VAR]
          [VAR name="responsabileNominativo" type="string"][VALUE_OF varname="responsabileIterable" index="firstItem" /][/VAR]

          [% elencoResponsabiliCsv = elencoResponsabiliCsv + responsabileNominativo; %]
          [% responsabileIdx = responsabileIdx + 1; %]

          [IF]
              [CONDITION][% responsabileIdx < elencoResponsabiliCount %][/CONDITION]
              [THEN]
                  [% elencoResponsabiliCsv = elencoResponsabiliCsv + ", "; %]
              [/THEN]
          [/IF]
        [/DO][/WHILE]

        [%= elencoResponsabiliCsv %]
        [/EFTL]
        `);

settings:
  encodeUrl: true
  timeout: 0
  followRedirects: true
  maxRedirects: 5
  forwardAuthorizationHeader: true
