KrissyKrissy
8 years agoQrew Cadet
Remove duplicates from Concatenated Child to Parent Field - Involves Javascript
I have a field that is using Dan Diebolt's IOL technique that is Concatenating child fields to the parent record into one combined field. I would like for this field to remove all duplicates and blanks. Can someone please help? Field 173 that is being combined might say the same thing in each record so it is repeating in my combined field and I want it to only be listed once. Field 173 may also be blank and I do not want the blank spaces in the combined field. I appreciate any help! Thank you!
Here is the code I am using:
(function(){
var XMLFlatToObj = function(xml, type) {
var data = [];
var record = {};
$("record", xml).each(function() {
record = {};
$(this).children().each(function () {
record[$(this).prop("tagName")] = $(this).text();
});
data.push(record);
});
return {records: data};
}
var dbid = "bjvehdwbq";
var dbidParents = "bjvehdwcb";
var dbidChilds = "bjvehdwcj";
var apptoken = "d5ju6zccf9kf3bdbi87gsj8yz8m";
$.ajaxSetup({data: {apptoken: apptoken}});
var rids = $("span.QBU_Childs").map(function() {
return this.dataset.rid;
}).get();
var n= 100;
var ridsChunked = _.chain(rids).groupBy(function(element, index){
return Math.floor(index/n);
}).toArray().value();
_.each(ridsChunked, function(rids, index) {
var query = "{22.EX." + rids.join("}OR{22.EX.") + "}"
$.ajax({
url: dbidChilds,
data: {
act: "API_DoQuery",
clist: "3.22.173",
query: query
},
dataFilter: XMLFlatToObj
}).then(function(resp) {
var childsData = _.groupBy(resp.records, function(items) {
return items["related_lot"];
});
_.each(childsData, function(item, rid) {
$("span.QBU_Childs[data-rid=" + rid + "]").html( _.pluck(item, "combined_defects").join("<span style='color:red;'> | </span>") );
});
});
});
})();
Here is the code I am using:
(function(){
var XMLFlatToObj = function(xml, type) {
var data = [];
var record = {};
$("record", xml).each(function() {
record = {};
$(this).children().each(function () {
record[$(this).prop("tagName")] = $(this).text();
});
data.push(record);
});
return {records: data};
}
var dbid = "bjvehdwbq";
var dbidParents = "bjvehdwcb";
var dbidChilds = "bjvehdwcj";
var apptoken = "d5ju6zccf9kf3bdbi87gsj8yz8m";
$.ajaxSetup({data: {apptoken: apptoken}});
var rids = $("span.QBU_Childs").map(function() {
return this.dataset.rid;
}).get();
var n= 100;
var ridsChunked = _.chain(rids).groupBy(function(element, index){
return Math.floor(index/n);
}).toArray().value();
_.each(ridsChunked, function(rids, index) {
var query = "{22.EX." + rids.join("}OR{22.EX.") + "}"
$.ajax({
url: dbidChilds,
data: {
act: "API_DoQuery",
clist: "3.22.173",
query: query
},
dataFilter: XMLFlatToObj
}).then(function(resp) {
var childsData = _.groupBy(resp.records, function(items) {
return items["related_lot"];
});
_.each(childsData, function(item, rid) {
$("span.QBU_Childs[data-rid=" + rid + "]").html( _.pluck(item, "combined_defects").join("<span style='color:red;'> | </span>") );
});
});
});
})();