BAO Developer API for Flex Token Authentication

1358
3
Jump to solution
01-19-2012 06:47 AM
SethTum
New Contributor
I'm developing a widget for the Flex Viewer that accesses BAO reports.  I am able to make a service call to return the specified report, but I can only make 1 successful service call per session.  The service call fails if I try to make another call and bring back another report. On the second call, the site either crashes with an error message, or It hangs.  Here's some code that I use to make the service call with.  I'm not sure if the token is only valid for one service call or if I need to re validate my credentials for each call.

//Generates a report based on polygon
     if(geom)
     {
      /**
       * Create summary reports task parameters
       */
      var paramsPoly:SummaryReportsParameters = new SummaryReportsParameters();
      var features:Array = new Array();
      var feature:Graphic = new Graphic(geom);
      feature.attributes = {
       "AREA_ID": "custom1",
       "AREA_DESC": "Custom map drawn polygon",
       "STOREID": "1"
      };
      features.push(feature);
      var featureSet:FeatureSet = new FeatureSet(features);
      featureSet.geometryType = Geometry.POLYGON;
      featureSet.spatialReference = geom.spatialReference;
     
      // package FeatureSet as a Boundaries object
      paramsPoly.boundaries = new Boundaries(featureSet);
     
      // one or more reports can be specified
      var reportOptions:ReportOptions = new ReportOptions();
      // see GetReportTemplates for a list of available report templates
      // set the template name to the selected report template
      reportOptions.templateName = cmbReports.selectedItem.name;
      // set the report format to the selected report format
      reportOptions.format = cmbRptFormatTypes.selectedItem;
     
      // customize report headers
      var reportHeader : ReportHeader = new ReportHeader("Generated with the Business Analyst Online API for Flex");
      reportHeader.locationName = "Summary Reports";
      reportHeader.address1 = "Business Analyst Online API";
      reportHeader.address2 = "www.esri.com/baoapi";
      reportOptions.header = reportHeader;
      paramsPoly.reportOptions = [reportOptions];
     
      //  We only need the output report.  We don't need the output geometry
      //  because we already have it on the client.
      var outputTypesPoly:OutputTypes = new OutputTypes();
      outputTypesPoly.getReport = true;
      paramsPoly.outputTypes = outputTypesPoly;
     
      //set the outputSpatialReference parameter (as of version 2.1) to the spatial reference of the map
      paramsPoly.outputSpatialReference = map.spatialReference;
     
      var summaryReportsTask : SummaryReportsTask = new SummaryReportsTask();
      summaryReportsTask.token = token;
      summaryReportsTask.execute(paramsPoly, new mx.rpc.Responder(
       function(event:BATaskCompletedEvent):void
       {
        var taskResultOutput : TaskResultOutput = event.result as TaskResultOutput;
       
        var reportInfo : ReportInfo = taskResultOutput.reports[0];
        //openReportBtn.visible = true;
        //Open Report in Browser
        navigateToURL(new URLRequest(reportInfo.url), "_blank");
        cursorManager.removeBusyCursor();
       },
       function(event:FaultEvent):void
       {
        Alert.show("There was an error executing the Summary Reports task: " + event.fault.faultString);
        cursorManager.removeBusyCursor();
       }));
     
     }
0 Kudos
1 Solution

Accepted Solutions
SethTum
New Contributor
I figured out my issue.  After using fiddler I was reviewing my service request call to see what was being sent.  Turns out that after the first call, all the parameters were being passed correctly.  After making a second call, I was receiving an error that there were null parameters so after investigating which parameters were null, it seems that all the values that I was passing from my combo box selected values became undefined.  To fix the issue, I set all my combo boxes to the property requireSelection="true", so no null values would ever be passed during a service call even if the user made no selection changes.  It would at least default to the 1st item if the user didn't' change any default selections.

View solution in original post

0 Kudos
3 Replies
MehakSujan
New Contributor
Can you explain what you mean by it fails? Is there an error from the server that you can intercept using Fiddler? If so, could you send me that error?
With the Summary Reports sample on the Resource Center at http://help.arcgis.com/en/businessanalyst/online%20apis/apis/flex/samples/index.html?sample=SummaryR..., you can make multiple SummaryReports requests after being authenticated only once, by selecting different reports each time for the currently drawn polygon. Is this what you are looking for?
0 Kudos
SethTum
New Contributor
I figured out my issue.  After using fiddler I was reviewing my service request call to see what was being sent.  Turns out that after the first call, all the parameters were being passed correctly.  After making a second call, I was receiving an error that there were null parameters so after investigating which parameters were null, it seems that all the values that I was passing from my combo box selected values became undefined.  To fix the issue, I set all my combo boxes to the property requireSelection="true", so no null values would ever be passed during a service call even if the user made no selection changes.  It would at least default to the 1st item if the user didn't' change any default selections.

View solution in original post

0 Kudos
MehakSujan
New Contributor
Excellent, glad you figured it out :).
0 Kudos