Sum of data show in list of dictionary

Certified Associate Developer

Hiii,

I want to add the Total Cost . It show the data in below format. I am using sum function to add the data but it is not working.

List of Dictionary - 7 items

    • Dictionary
        • Total_Cost19000(Number (Integer))
          • Dictionary
              • Total_Cost18000(Number (Integer))
                • Dictionary
                    • Total_Cost15000(Number (Integer))
                      • Dictionary
                          • Total_Cost7000(Number (Integer))
                            • Dictionary
                                • Total_Cost9000(Number (Integer))
                                  • Dictionary
                                      • Total_Cost13000(Number (Integer))
                                        • Dictionary
                                            • Total_Cost1500(Number (Integer))

                                            Discussion posts and replies are publicly visible

                                          • 0
                                            Certified Lead Developer
                                            but it is not working.

                                            What exactly does this mean? And, can you share your code?

                                          • 0
                                            Certified Lead Developer

                                            a!localVariables(
                                              local!dictionary: {
                                                {
                                                  totalCost: 1000
                                                },
                                                {
                                                  totalCost: 2000
                                                },
                                                {
                                                  totalCost: 3000
                                                }
                                              },
                                              sum(local!dictionary.totalCost)
                                            )
                                            

                                          • 0
                                            Certified Associate Developer
                                            in reply to Stefan Helzle

                                            This is the Code

                                            a!localVariables(
                                            local!CostData: a!queryEntity(
                                            entity: cons!ERV_dataEntity,
                                            query: a!query(
                                            selection: a!querySelection(
                                            columns: a!queryColumn(field: "totalCost", alias: "Total_Cost")
                                            ),
                                            logicalExpression: a!queryLogicalExpression(
                                            operator: "AND",
                                            filters: {
                                            a!queryFilter(field: "totalCost", operator: "not null"),
                                            a!queryFilter(
                                            field: "rmApproval",
                                            operator: "=",
                                            value: true
                                            )
                                            }
                                            ),
                                            pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 20)
                                            )
                                            ).data,
                                            local!CostData
                                            )

                                             And see below this is the output and I want to add all the total Cost Value.

                                            List of Dictionary - 7 items

                                              • Dictionary
                                                  • Total_Cost19000(Number (Integer))
                                                    • Dictionary
                                                        • Total_Cost18000(Number (Integer))
                                                          • Dictionary
                                                              • Total_Cost15000(Number (Integer))
                                                                • Dictionary
                                                                    • Total_Cost7000(Number (Integer))
                                                                      • Dictionary
                                                                          • Total_Cost9000(Number (Integer))
                                                                            • Dictionary
                                                                                • Total_Cost13000(Number (Integer))
                                                                                  • Dictionary
                                                                                      • Total_Cost1500(Number (Integer))

                                                                                  • 0
                                                                                    Certified Lead Developer
                                                                                    in reply to pranavk513816

                                                                                    This makes your code more readable.

                                                                                    Did you consider to do that aggregation directly in the query?

                                                                                    If this does not work for you,  has the solution.

                                                                                  • 0
                                                                                    Certified Associate Developer
                                                                                    in reply to Stefan Helzle

                                                                                    a!localVariables(
                                                                                      local!emailData: a!queryEntity(
                                                                                        entity: cons!ERV_dataEntity,
                                                                                        query: a!query(
                                                                                          selection: a!querySelection(
                                                                                            columns: a!queryColumn(field: "totalCost", alias: "Total_Cost")
                                                                                          ),
                                                                                          logicalExpression: a!queryLogicalExpression(
                                                                                            operator: "AND",
                                                                                            filters: {
                                                                                              a!queryFilter(field: "totalCost", operator: "not null"),
                                                                                              a!queryFilter(
                                                                                                field: "rmApproval",
                                                                                                operator: "=",
                                                                                                value: true
                                                                                              )
                                                                                            }
                                                                                          ),
                                                                                          pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 20)
                                                                                        )
                                                                                      ).data,
                                                                                      local!emailData
                                                                                    )

                                                                                    a!localVariables(
                                                                                      local!emailData: a!queryEntity(
                                                                                        entity: cons!ERV_dataEntity,
                                                                                        query: a!query(
                                                                                          selection: a!querySelection(
                                                                                            columns: a!queryColumn(field: "totalCost", alias: "Total_Cost")
                                                                                          ),
                                                                                          logicalExpression: a!queryLogicalExpression(
                                                                                            operator: "AND",
                                                                                            filters: {
                                                                                              a!queryFilter(field: "totalCost", operator: "not null"),
                                                                                              a!queryFilter(
                                                                                                field: "rmApproval",
                                                                                                operator: "=",
                                                                                                value: true
                                                                                              )
                                                                                            }
                                                                                          ),
                                                                                          pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 20)
                                                                                        )
                                                                                      ).data,
                                                                                      local!emailData
                                                                                    )