On Multiple Entries


TDI works best with exact matches. But sometimes this isn't possible. So what do you do when you get the exception below?  You use the On Multiple Entries hook in your connector.

CTGDIS048E Multiple entries found and no 'On Multiple Entries' Hook defined.

Viewing

Here's a simple snippet to show you what you've got

var thisEntry = thisConnector.getFirstDuplicateEntry();

while ( thisEntry != null) {

    task.logmsg(thisEntry.someAttribute);

    thisEntry = thisConnector.getNextDuplicateEntry();
}

The above is great for at least showing you what is going on or getting data out of the entires.  But let's say you want to update these multiple entries. That's harder because the act of updating any one of the duplicate entries resets the DuplicateEntry method. In this case you need to copy them first.

Updating

Updating is a little harder because it's a two-step process. You must first copy the primary keys of the duplicate objects, then go update them. This is because when the connector detects an update, it deletes the existing array of duplicates.

In this example, we iterate through the duplicate entries from a database store and add their primary keys to an array. Then we iterate over that array and update each one with the values already stored in the work entry. The search criteria is somewhat esoteric, but here are some examples of that if it's confusing.

// Pull out the duplicate keys

var keys = [];

var thisEntry = thisConnector.getFirstDuplicateEntry();

while ( thisEntry != null) {

    keys.push(thisEntry.MD_PERSON_KEY.getValue());

    thisEntry = thisConnector.getNextDuplicateEntry();
}


// Modify the records

for (i in keys) {

    var theCriteria = new com.ibm.di.server.SearchCriteria("MD_PERSON_KEY", 61, keys[i]);

    try {
        
        thisConnector.getConnector().modEntry(work,theCriteria);

        task.logmsg("Updated " + keys[i]);
    }

    catch (Ex){
    
        task.logmsg("Error updating this entry ");

        task.logmsg("ERROR: " + Ex.getMessage());

        task.dumpEntry(work);
    }
}



Let's say you want to wrap a little change detection?

// Modify the records

for (i in keys) {

    var theCriteria = new com.ibm.di.server.SearchCriteria("MD_PERSON_KEY", 61, keys[i]);

    try {                

        var resultEntry = thisConnector.getConnector().findEntry(theCriteria);
        
        if (resultEntry != null) {        
               
        if (resultEntry.SOME_ATTR.getValue() == work.SOME_ATTR.getValue()) {
        task.logmsg("INFO","No changes required");        
        }
        else {
        thisConnector.getConnector().modEntry(work,theCriteria);
        task.logmsg("Updated " + work.SOME_OTHER_ATTR + " " + keys[i]);        

        }
                     
        }        
    }

    catch (Ex){
    
        task.logmsg("Error updating this entry ");

        task.logmsg("ERROR: " + Ex.getMessage());

        task.dumpEntry(work);
    }
}


Deleting

Let's say you want to delete the invalid entries 


TODO





DELETE from table_name WHERE some_column=some_value

var thisEntry = thisConnector.getFirstDuplicateEntry();
var nextEntry = thisConnector.getNextDuplicateEntry();

while ( nextEntry != null) {


    if ( thisEntry.DATE_YEAR.getValue() < nextEntry.DATE_YEAR.getValue() )    {   // be careful when comparing order of strings!

        var recordIDValue = thisEntry.RECORD_ID.getValue();

        var theCriteria = new com.ibm.di.server.SearchCriteria("RECORD_ID",61,recordIDValue);

        thisConnector.getConnector().deleteEntry(thisEntry,theCriteria);

    }

    else {

    // do the same thing but in reverse


    }

    var thisEntry = thisConnector.getFirstDuplicateEntry();
    var nextEntry = thisConnector.getNextDuplicateEntry();

}





Here's an example - in this case I am deleting the offending entry and restarting the assembly line on the current Entry.


task.logmsg("WARN","Multiple Entries for " + work.CNS_NETID);

task.logmsg("INFO","Duplicate Count: " + thisConnector.getDuplicateEntryCount());

while ( (thisEntry = thisConnector.getNextDuplicateEntry() ) != null) {
if (! thisEntry.MD_DATA_SOURCE) {
task.logmsg("WARN","No MD_DATA_SOURCE, cannot process multiple entries");
}
else {
var dataSource = thisEntry.MD_DATA_SOURCE.getValue();
task.logmsg("INFO","Data Source of Entry: " + dataSource);
if (dataSource == "OEB") {
task.logmsg("INFO","Deleting OEB entry for this person");
var personKey = thisEntry.MD_PERSON_KEY.getValue();
var theCriteria = new com.ibm.di.server.SearchCriteria("MD_PERSON_KEY",61,personKey);
thisConnector.getConnector().deleteEntry(thisEntry,theCriteria);
task.logmsg("INFO","Restarting with this person");
system.restartEntry();
}
}

}
Comments