Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:32:59+00:00 2026-05-30T16:32:59+00:00

I have a ColdFusion method getData() which returns a query object as follows: CustomerCode

  • 0

I have a ColdFusion method getData() which returns a query object as follows:

CustomerCode  ServiceCode  SubscriberCode  Status    UserName
-------------------------------------------------------------
811101        8            gertjan         OPEN      gertjan@blah.net
811101        8            gertjan         CLOSING   gertjan@blah.net
811101        2            99652444        CLOSED    gertjan@blah.net
811101        2            99655000        OPEN      gertjan@blah.net

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:33:00+00:00Added an answer on May 30, 2026 at 4:33 pm

    You would need to keep a hash as you read the data, ignoring data if an ‘OPEN’ was already found. Then loop through the hash items and output the data:

    if(res.ROWCOUNT > 0){
        var hash = {};  // Hash to store data
        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')){
                 if( hash[SubscriberCode] != undefined && hash[SubscriberCode].status == 'OPEN' ) {
                     // If we already have OPEN, don't load the data
                     continue;
                 } else {
                     // Else override whatever data you have for this SubscriberCode
                     hash[SubscriberCode] = { status: Status, subscriber: SubscriberCode, service: ServiceCode }; 
                 }
            }
        }
    
        // loop through the hash and output the options
        for(var x in hash) {
            lines.push(hash[x].subscriber);
            $('#selInternet').append(
                $('<option></option>').val(hash[x].subscriber).html(hash[x].subscriber)
            );
        }
    
        global_internet_lines = lines;
        if(lines.length == 0){
            $('#divBroadbandUsage').html('No Active Broadband Connections.');
        }
    }
    

    I’m not sure what your cases are, but this covers your description I believe. I realize it is silly to have the hash key stored in the data, but for demonstration, this is how you would retrieve other data. This code stores Status, SubscriberCode, and ServiceCode, but your example only uses SubscribercCode. If this is really the case, it is much simpler:

    if(res.ROWCOUNT > 0){
        var hash = {};  // Hash to store data
        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')){
                 // If we see the subscriber code, add it to our hash
                 hash[SubscriberCode] = 1; 
            }
        }
    
        // loop through the hash and output the options
        for(var sub in hash) {
            lines.push(sub);
            $('#selInternet').append(
                $('<option></option>').val(sub).html(sub)
            );
        }
    
        global_internet_lines = lines;
        if(lines.length == 0){
            $('#divBroadbandUsage').html('No Active Broadband Connections.');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ColdFusion function foo which takes three args, and the second two
I have a ColdFusion script that does: <cfset content = replace(content,&##147;,,all)> Which replaces &147;
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
I'm new to coldfusion. I have page called test1.cfm <form action = test2.cfm method
I have some ColdFusion code which calls a function in a Java class via:
I have a loop in Coldfusion which will run for a long time; about
i have a coldfusion cfc and some methods in it. MethodA will return a
We have a medium sized ColdFusion code base for our Intranet and Website. For
I have started design of a ColdFusion application that is entirely web based. Not
i have some questions about constructors in ColdFusion : must i use the name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.