3 Replies Latest reply on Sep 6, 2007 10:51 AM by aceinc

    Bug? in httpservice.

      I am relatively new to Flex, and the person who gave me a jump start provided sample code to do various common things, one of which was to handle the lastResults from an HTTPService call. Basically it looks like this;

      <mx:HTTPService id="vendorSearch"
      url="{ RootDomain + xxx.aspx' }"
      useProxy="false" showBusyCursor="true" method="GET"

      ... the function vendorSearchResults contains ...

      if(Number(vendorSearch.lastResult.DataSet.recordcount) > 1)
      acVendorSummary = vendorSearch.lastResult.DataSet.VendorSummary;
      acVendorSummary.removeAll(); /* clear grid before adding the record.
      add a single record to the grid manually,
      this is because an ArrayCollection cannot
      be populated from a service call that contains
      only a single record
      VENDOR_CLASSIFICATION:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_CLASSIFICATION ,

      The part that I do not understand is why is the object returned from the HTTPService request different when there is one record vs more than one?

      When I try to execute;

      acVendorSummary = vendorSearch.lastResult.DataSet.VendorSummary;

      when there is one record I get a type coercion error, it can't convert the lastresult to a an ArrayCollection. When I look at the variables in debug, last result seems to look ok.

      My main questions are;

      1) Is this a bug?

      2) Is there a better way to handle the problem than the way I am doing it? How?

        • 1. Re: Bug? in httpservice.
          aceinc Level 1
          I see that no one is paying attention, so I thought I would pop this topic to the top of the list ...

          • 2. Re: Bug? in httpservice.
            kcell Level 2
            Hi Paul,

            you can check if the result is an arraycollection with the something like

            if (vendorSearch.lastResult.DataSet is ArrayCollection )
            //yupie it is an arraycollection
            // its just an object ?

            If its just an object, create an new arraycollection and add the one item through it as you did, but it should be enough to code something like

            best regards
            • 3. Re: Bug? in httpservice.
              aceinc Level 1
              Two notes...

              1) Prior to doing the additem, do "acVendorSummary.removeAll();"

              2) You didn't go quiute deep enough, it should have been, acVendorSummary.addItem(vendorSearch.lastResult.DataSet.VendorSummary);

              Howerver what you provided was the answer that I needed. Thanks kcell.