I have a ColdFusion method getData() which returns a query object as follows:
CustomerCode ServiceCode SubscriberCode Status UserName
-------------------------------------------------------------
811101 8 gertjan OPEN [email protected]
811101 8 gertjan CLOSING [email protected]
811101 2 99652444 CLOSED [email protected]
811101 2 99655000 OPEN [email protected]
Note the first two rows - exactly the same except for Status OPEN and CLOSING respectively.
The following function creates a new select option for each row where ServiceCode=8 and Status is either OPEN or CLOSING, which would be the case for both the first two rows.
The data ultimately comes via a web service which is out of my control to change. I need to change the jQuery such that if BOTH an OPEN and CLOSING record exists for the same ServiceCode/SubscriberCode combination, which is the case for the first two rows, then only create an option for the OPEN record.
function getInternetLines(){
var CustomerCode=global_customerCode;
var SessionID=global_sessionID;
var lines=[];
$.getJSON("/system.cfc?method=getData&returnformat=json&queryformat=column",
{"SessionID":SessionID,"CustomerCode":CustomerCode},
function(res,code) {
if(res.ROWCOUNT > 0){
for(var i=0; i<res.ROWCOUNT; i++) {
var ServiceCode = res.DATA.ServiceCode[i];
var SubscriberCode = res.DATA.SubscriberCode[i];
var Status = res.DATA.Status[i];
if(ServiceCode == 8 && (Status == 'OPEN' || Status == 'CLOSING')){
lines.push(SubscriberCode);
$('#selInternet').append(
$('<option></option>').val(SubscriberCode).html(SubscriberCode)
);
}
}
global_internet_lines = lines;
if(lines.length == 0){
$('#divBroadbandUsage').html('No Active Broadband Connections.');
}
}else{
$('#divBroadbandUsage').html('No Active Broadband Connections.');
}
});
}
HTML
<select name="selInternet" id="selInternet" style="width:120px">
</select>
Any assistance greatly appreciated in getting the cleanest approach to this, without multiple loops of the same dataset, for example.