Need to manipulate the array

Certified Associate Developer

local!data: {
{ name: "John", status: "Active", test: 10 },
{ name: "John", status: null, test: 4 },
{ name: "Alice", status: "Active", test: 5 },
{ name: "Alice", status: null, test: 6 },
{ name: "Bob", status: null, test: 8 }
}

This a the above data now my requirement is remove null status only for the duplicate name and transfer the test value to the non-null status.

Can any one please help me with this.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    hi,

    So you want to remove the duplicate null with null status right. Hope the code will help

    a!localVariables(
      local!data: {
        { name: "John", status: "Active", test: 10 },
        { name: "John", status: null, test: 4 },
        { name: "Kiran",status: null, test: 10},
        { name: "Kiran",status: "Active", test: 10},
        { name: "Alice", status: "Active", test: 5 },
        { name: "Alice", status: null, test: 6 },
        { name: "Bob", status: null, test: 8 }
      },
      local!uniqueNames:union(index(local!data,"name",null),index(local!data,"name",null)),
      local!DuplicateUsers:reject(fn!isnull,a!forEach(
        items: local!uniqueNames,
        expression: if(
          count(wherecontains(touniformstring(fv!item),touniformstring(index(local!data,"name",null))))>1,
          fv!item,
          null()
        )
      )),
      local!duplicateUserIndexes:index(local!data,wherecontains(
        touniformstring(local!DuplicateUsers),
        touniformstring(index(local!data,"name",null))
      ),null),
      reject(fn!isnull,a!forEach(
        items: local!duplicateUserIndexes,
        expression: if(
          touniformstring(index(fv!item,"status",null))=touniformstring(null),
          null,
          fv!item
        )
      ))
    )

Reply
  • 0
    Certified Senior Developer

    hi,

    So you want to remove the duplicate null with null status right. Hope the code will help

    a!localVariables(
      local!data: {
        { name: "John", status: "Active", test: 10 },
        { name: "John", status: null, test: 4 },
        { name: "Kiran",status: null, test: 10},
        { name: "Kiran",status: "Active", test: 10},
        { name: "Alice", status: "Active", test: 5 },
        { name: "Alice", status: null, test: 6 },
        { name: "Bob", status: null, test: 8 }
      },
      local!uniqueNames:union(index(local!data,"name",null),index(local!data,"name",null)),
      local!DuplicateUsers:reject(fn!isnull,a!forEach(
        items: local!uniqueNames,
        expression: if(
          count(wherecontains(touniformstring(fv!item),touniformstring(index(local!data,"name",null))))>1,
          fv!item,
          null()
        )
      )),
      local!duplicateUserIndexes:index(local!data,wherecontains(
        touniformstring(local!DuplicateUsers),
        touniformstring(index(local!data,"name",null))
      ),null),
      reject(fn!isnull,a!forEach(
        items: local!duplicateUserIndexes,
        expression: if(
          touniformstring(index(fv!item,"status",null))=touniformstring(null),
          null,
          fv!item
        )
      ))
    )

Children
No Data