info:
  name: Recupero importo richiedente da proposta
  type: http
  seq: 27

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: "22737"
      disabled: true
    - name: x-ef-request-id
      value: "22224"
      disabled: true
    - name: x-ef-request-id
      value: "23663"
      disabled: true
    - name: x-ef-request-id
      value: "23698"
  body:
    type: json
    data: |-
      {
        "userDocument": "{{elixBase64EftlDocument}}", // see the pre-request script
        "userContext": {
          "lang": "IT",
          "crlf": "\r\n",
          "useTestCF": false
        }
      }
  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="codiceFiscaleRichiedente" type="string"][TAG]GETVALUEBYTAG,RICHIEDENTE_CODFIS,REQUEST,IUQOID[/TAG][/VAR]
        [VAR name="ripartizioniIterable" type="iterable"][SPLIT regex="#"][TAG]GETVALUEBYTAG,COPPIE_RIPARTIZIONI,REQUEST,IUQOID,CONCAT,#[/TAG][/SPLIT][/VAR]

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

        [FOR varname="coppia" iterable="ripartizioniIterable"]
          [VAR name="coppiaiIterable" type="iterable"][SPLIT regex=":"][VALUE_OF varname="coppia" /][/SPLIT][/VAR]
          [VAR name="codiceFiscale" type="string"][VALUE_OF varname="coppiaiIterable" index="firstItem" /][/VAR]
          [VAR name="importo" type="number"][VALUE_OF varname="coppiaiIterable" index="secondItem" /][/VAR]

          [IF]
            [CONDITION][% codiceFiscale == codiceFiscaleRichiedente %][/CONDITION]
            [THEN][% importoRichiedente = importo; %][/THEN]
          [/IF]
        [/FOR]

        [!--
        [%= importoRichiedente %]
        --]

        [FORMAT type="number" pattern="0.00"][% importoRichiedente %][/FORMAT]
        [/EFTL]
        `);

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

docs: |-
  SchemaId 709
  Campo COL0118
