Skip to main content
January 8, 2025
Question

change the result of the map data

  • January 8, 2025
  • 5 replies
  • 0 views
  • Map
      • mailList of Text String - 3 items
          • "test@gmail.com:1"(Text)
              • "test2@gmail.com:3"(Text)
                  • "test3@gmail.com:3"(Text)
                    • period"01/2024"(Text)
                      • Map
                          • mail "test4@gmail.com:4"(Text)

                              • period"01/2024"(Text)

                            above is the result of expression rule i want to remove mail  and make value like test@gmail.com as key and numbers that are after : as value 

                            and leave period as is 

                            • Map
                              • "test@gmail.com:1"(Text)
                              • "test@gmail.com:1"(Text)
                              • "test@gmail.com:1"(Text)
                              • period"01/2024"(Text) can i get result as this 

                              5 replies

                              harshas2775
                              January 9, 2025

                              Would be in better position to help if you paste the code responsible or explain the output better. Example, first map has 3 emails in it but the expected output you are expecting has just the first email but thrice (why?) and what happens to the other two emails within first map 

                              • "test2@gmail.com:3"(Text)
                                  • "test3@gmail.com:3"(Text)
                                  stefanhelzle0001
                                  January 9, 2025

                                  You can use the a!update() function to create a map with dynamic key names.

                                  amaans4178
                                  January 9, 2025
                                  • Duplicate keys are not allowed in a map or dictionary.
                                  • You can use the a!update() function to create dynamic keys, as Stefan mentioned in his reply. You can refer to this example for guidance.


                                    a!localVariables(
                                      local!returnedDataFromRule: {
                                        a!map(
                                          mail: {
                                            "test1@gamil.com:1",
                                            "test2@gamil.com:2",
                                            "test3@gamil.com:3"
                                          },
                                          period: "01/2024"
                                        ),
                                        a!map(
                                          mail: { "test@gamil.com:4",  },
                                          period: "01/2024"
                                        )
                                      },
                                      local!keysAndValues: a!forEach(
                                        items: a!flatten(
                                          property(local!returnedDataFromRule, "mail", "")
                                        ),
                                        expression: a!map(
                                          key: split(fv!item, ":")[1],
                                          value: split(fv!item, ":")[2]
                                        )
                                      ),
                                      a!update(
                                        data: a!map(),
                                        index: { property(local!keysAndValues, "key", "") },
                                        value: {
                                          property(local!keysAndValues, "value", ""),
                                          
                                        }
                                      ),
                                      
                                    )
                                  January 9, 2025

                                  Hi Eren,

                                  Thanks for the reply, I need Period value Aswell along with emails  

                                  for example, 

                                  • test@gmail.com:1"(Text)
                                  • "test@gmail.com:1"(Text)
                                  • "test@gmail.com:1"(Text)
                                  • period"01/2024"(Text)

                                  Thanks in Advance.

                                  amaans4178
                                  January 9, 2025

                                  Hi Mufeeda,
                                  In your example data i can see multiple periods ,but in output you want only one ? if yes then what is the period id that you want ? if no then as I mentioned above we can not have duplicate keys.

                                  below is the code for getting all the unique period valus 


                                  a!localVariables(
                                    local!returnedDataFromRule: {
                                      a!map(
                                        mail: {
                                          "test1@gamil.com:1",
                                          "test2@gamil.com:2",
                                          "test3@gamil.com:3"
                                        },
                                        period: "01/2024"
                                      ),
                                      a!map(
                                        mail: { "test@gamil.com:4"},
                                        period: "01/2024" 
                                        
                                      )
                                    },
                                    local!keysAndValues: a!forEach(
                                      items: a!flatten(
                                        property(local!returnedDataFromRule, "mail", "")
                                      ),
                                      expression: a!map(
                                        key: split(fv!item, ":")[1],
                                        value: split(fv!item, ":")[2]
                                      )
                                    ),
                                    local!periods: a!flatten(
                                      property(local!returnedDataFromRule, "period", "")
                                    ),
                                    local!emails: a!update(
                                      data: a!map(),
                                      index: {
                                        property(local!keysAndValues, "key", ""),
                                        
                                      },
                                      value: {
                                        property(local!keysAndValues, "value", ""),
                                        
                                      }
                                    ),
                                    a!update(
                                      data: local!emails,
                                      index: "period",
                                      value: union(local!periods,local!periods)
                                    )
                                  )