Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

OnComplete transform script to delete the target table records

Rashmika BS
Tera Guru

Hi, 

 

We are trying to delete the records from target table post the import happens but this worked only for the first time but its not happening now and target table is being accumulated with lot of records. below is the query.,

 

var AGG_import_set_row = new GlideAggregate(map.source_table);
    AGG_import_set_row.addQuery("sys_import_set", source.sys_import_set);
    AGG_import_set_row.addQuery("sys_transform_map", map.sys_id);
    AGG_import_set_row.addQuery("sys_target_sys_id", "!=", "");
    AGG_import_set_row.groupBy("sys_target_table");
    AGG_import_set_row.groupBy("u_code");
    AGG_import_set_row.groupBy("u_id");
    AGG_import_set_row.query();

    while (AGG_import_set_row.next()) {
        var m_ids = [];

        var import_set_row = new GlideRecord(map.source_table);
        import_set_row.addQuery("sys_import_set", source.sys_import_set);
        import_set_row.addQuery("sys_transform_map", map.sys_id);
        import_set_row.addQuery("sys_target_sys_id", "!=", "");
        import_set_row.addQuery("sys_target_table", AGG_import_set_row.sys_target_table);
        import_set_row.addQuery("u_code", AGG_import_set_row["u_code"]);
        import_set_row.addQuery("u_id", AGG_import_set_row["u_id"]);
        import_set_row.query();

        while (import_set_row.next())
            m_ids.push(import_set_row.sys_target_sys_id + "");

        var u_collection_member = new GlideRecord("u_collection_member");
        u_collection_member.addQuery("u_cmdb_collection", import_set_row.sys_target_sys_id.u_cmdb_collection);
        u_collection_member.addQuery("sys_id", "NOT IN", m_ids);
        u_collection_member.query();

        u_collection_member.deleteMultiple();
    }

})(source, map, log, target);

 

0 REPLIES 0