Tuesday, October 22, 2013

How to Delete duplicate records using X++

static void DeleteDuplicateValues(Args _args)
    Set fieldset = new set(types::Integer);

    // create dictindex from unique index

    DictIndex dictIndex = new dictIndex (tablenum(PurchTable), indexnum(PurchTable,PurchIdx));

    // these are fields from index

    // add them to set  

    fieldset.add(fieldnum(PurchTable ,OrderAccount));
    //Can add multiple fields also
    //Note the index should Not be primary index it alternake key should be no

    // set allow duplicates


    //reenable duplicates

    //Can also handle timestatekey index
    //by ReleaseUpdateDB::indexAllowNoDupAndDateEffective(dictIndex,ValidTimeStateMode::NoGap);  
    info("Deletion done");

No comments:

Post a Comment