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

    Bug? in httpservice.

    aceinc Level 1
      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"
      result="vendorSearchResults(event)">
      <mx:request>
      <action>find</action>
      <type>{cmbType.value}</type>
      <name>{txtName.text.toUpperCase()}</name>
      <datefrom>{txtDateFrom.text}</datefrom>
      <dateto>{txtDateTo.text}</dateto>
      <status>{cmbStatus.value}</status>
      </mx:request>
      </mx:HTTPService>

      ... the function vendorSearchResults contains ...

      if(Number(vendorSearch.lastResult.DataSet.recordcount) > 1)
      {
      acVendorSummary = vendorSearch.lastResult.DataSet.VendorSummary;
      }
      else
      {
      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
      */
      acVendorSummary.addItem({
      VENDOR_NUMBER:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_NUMBER,
      VENDOR_NAME:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_NAME,
      VENDOR_CLASSIFICATION:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_CLASSIFICATION ,
      VENDOR_STATUS:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_STATUS,
      VENDOR_TOTAL:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_TOTAL,
      TRANSACTION_COUNT:vendorSearch.lastResult.DataSet.VendorSummary.TRANSACTION_COUNT});
      acVendorSummary.refresh();

      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?

      Paul
        • 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 ...

          Paul
          • 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
            else
            // 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
            ...
            acVendorSummary.addItem(vendorSearch.lastResult.DataSet);
            ...

            best regards
            kcell
            • 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.

              Paul