change the result of the map data

  • 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 

                                Discussion posts and replies are publicly visible

                              Parents
                                • 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", ""),
                                        
                                      }
                                    ),
                                    
                                  )
                              Reply
                                • 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", ""),
                                        
                                      }
                                    ),
                                    
                                  )
                              Children
                              • 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.

                              • 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)
                                  )
                                )