Groovy web console

subscribe to the feed Subscribe
to this
site
FindSelectFieldsChangeKeyValues (via #groovywebconsole)
tweet this snippet Tweet
this
script

FindSelectFieldsChangeKeyValues

Published 3 months ago by Anand Patil with tags find collect replace key
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def audits = [  [
    "id": 4892725,
    "contractId": 30,
    "parentKey": "30",
    "key": "58",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892724,
    "contractId": 30,
    "parentKey": "30",
    "key": "59",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892726,
    "contractId": 30,
    "parentKey": "30",
    "key": "60",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892727,
    "contractId": 30,
    "parentKey": "30",
    "key": "61",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892728,
    "contractId": 30,
    "parentKey": "30",
    "key": "62",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892729,
    "contractId": 30,
    "parentKey": "30",
    "key": "63",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892730,
    "contractId": 30,
    "parentKey": "30",
    "key": "64",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892731,
    "contractId": 30,
    "parentKey": "30",
    "key": "65",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892732,
    "contractId": 30,
    "parentKey": "30",
    "key": "66",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892733,
    "contractId": 30,
    "parentKey": "30",
    "key": "67",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892734,
    "contractId": 30,
    "parentKey": "30",
    "key": "68",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892735,
    "contractId": 30,
    "parentKey": "30",
    "key": "69",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892736,
    "contractId": 30,
    "parentKey": "30",
    "key": "70",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892737,
    "contractId": 30,
    "parentKey": "30",
    "key": "71",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892739,
    "contractId": 30,
    "parentKey": "30",
    "key": "72",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892738,
    "contractId": 30,
    "parentKey": "30",
    "key": "73",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892740,
    "contractId": 30,
    "parentKey": "30",
    "key": "74",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892741,
    "contractId": 30,
    "parentKey": "30",
    "key": "75",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892742,
    "contractId": 30,
    "parentKey": "30",
    "key": "76",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892743,
    "contractId": 30,
    "parentKey": "30",
    "key": "77",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892744,
    "contractId": 30,
    "parentKey": "30",
    "key": "78",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892745,
    "contractId": 30,
    "parentKey": "30",
    "key": "79",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892746,
    "contractId": 30,
    "parentKey": "30",
    "key": "80",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892747,
    "contractId": 30,
    "parentKey": "30",
    "key": "81",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892748,
    "contractId": 30,
    "parentKey": "30",
    "key": "82",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892749,
    "contractId": 30,
    "parentKey": "30",
    "key": "83",
    "tableName": "mt_dispatch",
    "changeType": "I"
  ],
  [
    "id": 4892723,
    "contractId": 30,
    "parentKey": "30",
    "key": "5",
    "tableName": "mt_dispatch",
    "changeType": "U"
  ],
  [
    "id": 4892702,
    "contractId": 30,
    "parentKey": "6",
    "key": "318381",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892703,
    "contractId": 30,
    "parentKey": "6",
    "key": "318382",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892704,
    "contractId": 30,
    "parentKey": "6",
    "key": "318383",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892705,
    "contractId": 30,
    "parentKey": "6",
    "key": "318384",
    "tableName": "mt_progress",
    "changeType": "I"
  ],
  [
    "id": 4892706,
    "contractId": 30,
    "parentKey": "6",
    "key": "318385",
    "tableName": "mt_progress2",
    "changeType": "I"
  ],
  [
    "id": 4892707,
    "contractId": 30,
    "parentKey": "6",
    "key": "318386",
    "tableName": "mt_progress2",
    "changeType": "I"
  ]
]

def dispatches = audits.findAll{it.tableName == 'mt_progress2'}.collect{it.subMap(["contractId","key"])}.each{it.put("dispatchId",it.remove("key"))}
println dispatches//.collectdispatches[0].remove("key"))}
//dispatches.each{it.put("dispatchId",it.remove("key"))}