Skip to main content
Inspiring
Sep 20, 2023 9:25 AM UTC
Solved

Is there a mistake in this forEach to get all data by id. Using rule

a!forEach(
items: pv!id,
expression: a!save(
rule!Test_getDossierByDossierId(
dossierId: fv!item,
pagingInfo: a!pagingInfo(1, - 1)
),
pv!id
).data
)

    Inspiring
    Sep 20, 2023 12:33 PM UTC

    I choose the first way because my rule!Test_getDossierByDossierId accepts one type rule input : dossierId

    9 replies

    stefanhelzle0001
    Brainy
    Sep 20, 2023 9:58 AM UTC

    Multiple:

    - Using a process variable in an a!save() seems not correct

    - What is that pv!id in line 8 doing?

    - Querying data in a loop is a bad performing anti-pattern

    Inspiring
    Sep 20, 2023 10:05 AM UTC

    In fact, I want to make a loop in a process variable "pv!id" to retrieve all data 

    dhananjayk3480
    Inspiring
    Sep 20, 2023 10:33 AM UTC

    Then just run loop like below, don't do a!save. Because you just need data

    a!forEach(
      items: pv!id,
      expression: rule!Test_getDossierByDossierId(
        dossierId: fv!item,
        pagingInfo: a!pagingInfo(1, - 1)
      ).data
    )

    Or if you rule rule!Test_getDossierByDossierId accepts multiple type rule input dossierId then you don't need to run loop

    rule!Test_getDossierByDossierId(
      dossierId: pv!id,
      pagingInfo: a!pagingInfo(1, - 1)
    ).data