Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
Remove duplicate rows based on 3 columns

The below code returns a table with values from a web list. Some values are duplicates. I need to remove all duplicates where "User_x0020_Name", "Previous_Total_Most_Likely_Forec", "Submitted_Total_Most_Likely_Fore" are the same and only keep the latest record (maximum of "Created") for a duplicates set.

function loadAuditTrailFinancials() {
    var auditTrailURL = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Audit_Trail_Financial_Data')/items?$select=Author/Title,Previous_Total_Most_Likely_Forec,Submitted_Total_Most_Likely_Fore,Forecast_Approval_Reason,Title,Created,Workflow_Stage_Name,WorkflowStageShort,Source,Event&$filter=Title eq '" + PDP_projUid + "'&$orderby=Created desc&$expand=Author/ID";
    console.log("loadAuditTrailFinancials:" + auditTrailURL);
    $.ajax({
            url: auditTrailURL,
            method: "GET",
            headers: {"Accept": "application/json; odata=verbose"},
            success:    function (data) {
                            var items = data.d.results;
                            for (var i = 0; i < items.length; i++) {
                                var creation_date = items[i].Created;                           
                                var current_user = items[i].User_x0020_Name;
                                console.log(items[i]);
                                $('#AuditTrailTable_Financial').append('<tr class="audit_content">' +
                                    '<td align=center>&nbsp;' + format_date(creation_date) + '&nbsp;</td>' +     
                                    '<td align=center>&nbsp;' + items[i].WorkflowStageShort+ '&nbsp;</td>' +
                                    '<td align=center>&nbsp;' + items[i].Author.Title + '&nbsp;</td>' +
                                    '<td align=center>&nbsp;' + items[i].Source + '&nbsp;</td>' +
                                    '<td align=center>&nbsp;' + items[i].Previous_Total_Most_Likely_Forec + '&nbsp;</td>' +
                                    '<td align=center>&nbsp;' + items[i].Submitted_Total_Most_Likely_Fore + '&nbsp;</td>' +
                                '</tr>');                               
                            }
                            $('.audit_content').hide();
                            console.log(data);
                        },
            error: function (data) { alert("Some error occurred in getting Audit Trail")}
    });

}   
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I haven't verified this but maybe you can do something like this:

Using a hash map to store index location of the unique triplet in order to replace it when we find a newer one.

// This will be our final result array, with no duplicates.
const result = []
// Here we will store the result index location of a stored item.
const latest_map = new Map()

// build a unique key for the triplet combo.
function buildKey(item) {
    const separator = "__"
    return item.User_x0020_Name + separator + item.Previous_Total_Most_Likely_Forec + separator + item.Submitted_Total_Most_Likely_Fore
}

// check if item exist, replace
function deduplicateAndKeepLatest(item) {
    const key = buildKey(item);
    if (latest_map.has(key)) {
        result[latest_map.get(key)] = item; // replace old item with latest.
    } else {
        result.push(item);
        latest_map.set(key, result.length-1) // first time seeing this item, save the index it was stored at.
    }
}

// make sure items is in the correct sort order, since you want to keep the latest.
items.forEach((item) => {
    deduplicateAndKeepLatest(item);
}

return result; // should contain unique triplet, and only latest one.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda