Cloud Pak for Data

 View Only
  • 1.  DATA RULE FOR DUPLICATE RECORD

    Posted Thu March 30, 2023 05:43 AM

    I want to write a data rule for finding the duplicate record in the asset can someone please help upon this?



    ------------------------------
    Akshay Nirmal
    ------------------------------


  • 2.  RE: DATA RULE FOR DUPLICATE RECORD

    Posted Tue January 02, 2024 12:38 PM

    To find duplicate records in an array of assets using PHP, you can use the following example. I'll assume that your assets are represented as an array of associative arrays, and you want to find duplicates based on a specific key within each asset.

    php
    <?php // Sample array of assets $assets = array( array('id' => 1, 'name' => 'Asset1', 'type' => 'TypeA'), array('id' => 2, 'name' => 'Asset2', 'type' => 'TypeB'), array('id' => 3, 'name' => 'Asset3', 'type' => 'TypeA'), array('id' => 4, 'name' => 'Asset4', 'type' => 'TypeB'), array('id' => 5, 'name' => 'Asset1', 'type' => 'TypeA'), // Duplicate ); // Function to find duplicate records based on a specific key function findDuplicateRecords($array, $key) { $uniqueRecords = array(); $duplicateRecords = array(); foreach ($array as $record) { $recordValue = $record[$key]; // If the record value is not in the unique array, add it if (!in_array($recordValue, $uniqueRecords)) { $uniqueRecords[] = $recordValue; } else { // If it's already in the unique array, it's a duplicate $duplicateRecords[] = $record; } } return $duplicateRecords; } // Specify the key for finding duplicates (e.g., 'name') $duplicateKey = 'name'; // Find duplicate records based on the specified key $duplicates = findDuplicateRecords($assets, $duplicateKey); // Output the duplicate records echo "Duplicate Records based on '$duplicateKey':\n"; print_r($duplicates); ?>

    This example defines a function findDuplicateRecords that takes an array of assets and a key for comparison. It then iterates through the array and identifies and returns duplicate records based on the specified key. The sample array of assets and the duplicate key are provided for illustration. You can modify the array and key based on your actual data structure. Currently, I am using this code on tatglam and I hope it will work for you. 



    ------------------------------
    amelia smith
    ------------------------------