Strategy ONE
Adding a Metric Sort
In this example, one metric sort is added for Qty Sold and element NY.
Code sample
Get the report instance of WebReportInstance type as shown in the example Retrieving a report instance. The DSSID for metric object Qty Sold is F9F68A8C11D5753EC000FDACBDDA374F, and the element ID for NY element is “BB:F9F68B5F11D5753EC000FDACBDDA374F:1:2:0:2:NY:1:2:12”. The element ID is obtained from the report grid.
WebTemplate wt = rptInst.getTemplate();
WebSorts sorts = wt.getAxis(EnumDSSXMLAxisName.DssXmlAxisNameRows).getSorts();
//Add a metric sort at the end of the sorts collection on the row axis
WebMetricSort metricSort = (WebMetricSort)sorts.add(EnumDSSXMLSortType.DssXmlSortMetric);
//creates the object information for the metric object
WebObjectInfo metricObj = wos.getObject("F9F68A8C11D5753EC000FDACBDDA374F",4);
//set the metric object information as the target in the metric sort object
metricSort.setTarget(metricObj);
//adds the NY element as the element in the metric sort object
metricSort.getElements().add("BB:F9F68B5F11D5753EC000FDACBDDA374F:1:2:0:2:NY:1:2:12"); //Rebuild the report and print it
WebInstance newInst = restoreInst.getManipulator().applyChanges();
Log.logger.log(Level.INFO, "new report: " + newInst.getResultsAsXML());
