Skip to main content
manavik105
July 3, 2025
Question

How to fetch data in sequence and run the process in a batch

  • July 3, 2025
  • 8 replies
  • 0 views

Hi All,

I have a use case where I'm querying data from database table of 100 records set in paging Info. Now, Once I pass this data from my rule to process model, I need to extract the records one by one, perform some action on them and write to DB and then loop back again in the same process model to fetch the 2nd row data and repeat this in batches. My question is how do I fetch the data from a batch of 100 records and to get only one row and then 2nd row and so on without using an MNI? Please advise. 

8 replies

sarathkumr268295
July 3, 2025

Did you consider looping inside the process model?

docs.appian.com/.../looping.html

shubhama926776
July 3, 2025



I need to extract the records one by one, perform some action on them and write to DB and then loop back again in the same process model to fetch the 2nd row data and repeat this in batches.

Instead of writing records one by one during processing, you should use a!forEach() to perform calculations on each record individually and collect all the processed results. Then, after the forEach completes, you can write all the processed records to the database in a single batch operation. This approach gives you the benefit of individual record processing while maintaining optimal database performance through batch writing, eliminating the need for MNI or complex looping patterns in your Appian process model.

harshas2775
July 3, 2025

Better way to achieve the same is querying the 100 records, do manipulation on them in an expression rule using a!foreach() and then pass the output of the rule in the write records node. 

manavik105
July 4, 2025

Thank you [mention:65b14048184a4eb5aff3a76c87b97431:e9ed411860ed4f2ba0265705b8793d05]  Could you please advise how to write this using a!foreach() function?

I have my expression rule as below and I'm trying to get 100 records in 1 batch to pass to the process model. Now I need to fetch the 1st row from this rule output into a process model - perform some action and then loop back to fetch the second row - perform some action, loop back third record to fetch 3rd row and so on until I reach my 100th record. 

Rule:

a!localVariables(
local!getData: a!queryEntity_22r2(
entity: cons!SAC_ENTITY_CLIENTCASES,
fetchTotalCount: true,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {

),
a!queryFilter(
field: "docsSent",
operator: "is null"
)
}
),
selection: a!querySelection(
columns: {
a!queryColumn(field: "caseId"),
a!queryColumn(field: "caseStatus"),
a!queryColumn(field: "clientName"),
a!queryColumn(field: "folderId")
}
),
pagingInfo: if(
rule!APN_isBlank(
ri!pagingInfo
),
a!pagingInfo(
startIndex: 1,
batchSize: 5,
sort: a!sortInfo(
field: "caseId",
ascending: true
)
),
ri!pagingInfo
),
)

),
local!getData
)

Output of the Rule saved into PV of type data subset in process model. 

  • startIndex1(Number (Integer))
      • batchSize10(Number (Integer))
          • sortList of SortInfo - 1 item
              • SortInfo
                  • field"caseId"(Text)
                      • ascendingtrue(Boolean)
                      • totalCount5(Number (Integer))
                          • dataList of Dictionary - 5 items
                              • Dictionary
                                  • caseId322(Number (Integer))
                                      • caseStatus"On-Hold/Request for Info"(Text)
                                            • clientName"user1520872"(Text)
                                                • folderId214625(Number (Integer))
                                                  • Dictionary
                                                      • caseId21326(Number (Integer))
                                                          • caseStatus"On-Hold/Request for Info"(Text)
                                                                • clientName"user1520872"(Text)
                                                                    • folderId154459(Number (Integer))
                                                                      • Dictionary
                                                                          • caseId21327(Number (Integer))
                                                                              • caseStatus"Ready For Underwriting"(Text)
                                                                                    • clientName"user1520872"(Text)
                                                                                        • folderId154458(Number (Integer))
                                                                                          • Dictionary
                                                                                              • caseId52046(Number (Integer))
                                                                                                  • caseStatus"Ready For Underwriting"(Text)
                                                                                                        • clientName"user1520872"(Text)
                                                                                                            • folderId154458(Number (Integer))
                                                                                                              • Dictionary
                                                                                                                  • caseId59106(Number (Integer))
                                                                                                                      • caseStatus"On-Hold/Request for Info"(Text)
                                                                                                                            • clientName"user1520872"(Text)
                                                                                                                                • folderId154459(Number (Integer))
                                                                                                                                • identifiersList of Number (Integer) - 5 items
                                                                                                                                    • 322(Number (Integer))
                                                                                                                                        • 21326(Number (Integer))
                                                                                                                                            • 21327(Number (Integer))
                                                                                                                                                • 52046(Number (Integer))
                                                                                                                                                    • 59106(Number (Integer))
                                                                                                                                                  July 4, 2025

                                                                                                                                                  HI. Try this inside a script task, and save the result in a map variable of type 'multiple'.

                                                                                                                                                  a!forEach(
                                                                                                                                                    items: pv!data.data,
                                                                                                                                                    /*adjust the logic based on your requirement*/
                                                                                                                                                    expression: a!update(
                                                                                                                                                      data: fv!item,
                                                                                                                                                      index: "caseStatus",
                                                                                                                                                      value: "ACTIVE"
                                                                                                                                                    )
                                                                                                                                                  )