Cookbook

This section provides a set of recipes for performing common reporting tasks.

You need a Form to collect user input for Named Parameters for the SQL query for Reporting Services based Reports.

A Client Method-based Report is used to present a Form to collect the user input. The user input is mapped to a query_string for the Report Server request via the RSGatwway.aspx page.

  1. Login to Aras Innovator as admin.
  2. Navigate to the Administration->Forms off the Main Tree.
  3. Open a new Form Item.
  4. Set the Form Item properties as follows:
    1. Name = My Report (this can be any name you want)
    2. Add a form event that fires onLoad
    3. Name the Method ‘My Report_setDefaults’ (this can be anything you want).

    4. Add fields to the form that will match the input you are requesting.
    5. Name the fields appropriately (‘PartNumber’, ‘Description’, ‘Cost’)

    6. Add a Button field with a label ‘Submit’
    7. Create a Field Event that fires onClick.

      Name the Method ‘My Report_OnClick’ (this can be anything you want)

    8. Save, unlock, and close.
  5. Navigate to the Administration->Methods off the Main Tree.
  6. Edit the My Report_OnClick Method Item.
  7. Set the method code as shown.
    1. Set document.forms[0].<FieldNameOnForm>.value to the names of the fields on the My Report Form.
    2. var retVal=[];

      // retVal will be used in MyReport_OpenDialog

      // document.forms[0].<FieldNameOnForm>.value

      retVal[“PartNum”] = document.forms[0].PartNumber.value;

      retVal[“Desc”] = document.forms[0].Description.value;

      retVal[“Cost”] = document.forms[0].Cost.value;

      parent.args.dialog.result = retVal;

      parent.args.dialog.close();

  8. Save, unlock, and close.
  9. Create another Method Item (‘MyReport_OpenDialog’, this can be called whatever you want).
  10. Set the method code as shown:
    1. Update var reportName with the name of your Report as deployed to the Report Server.
    2. The URL query strings (“&np:”) should reference the parameter as defined in the report.
  11. var inn = this.getInnovator();
  12. var ReportInputForm = inn.newItem(“Form”, “get”);
  13. ReportInputForm.setAttribute(“select”, “id, width, height”);
  14. ReportInputForm.setProperty(“keyed_name”, “My Report”);
  15. ReportInputForm = ReportInputForm.apply();
  16. var param =
  17. {
  18. title: “My Report”,
  19. formId: ReportInputForm.getID(),
  20. isEditMode: “1",
  21. aras: aras,
  22. opener: window,
  23. innovator: inn,
  24. // use param.item only if the Report is of Type=Item
  25. //and you need to pass the context item to the dialog
  26. //item : this
  27. dialogHeight: ReportInputForm.getProperty(‘height’,'800'),
  28. dialogWidth: ReportInputForm.getProperty(‘width’,'600'),
  29. content: ‘ShowFormAsADialog.html’
  30. };
  31. function callback (dialogWrapper)
  32. {
  33. var result = dialogWrapper.result;
  34. if (!result){ return }
  35. var reportName = “My Report"; // Your Report Name Here
  36. var url = top.aras.getServerBaseURL() + “RSGateway.aspx?irs:Report=" + reportName +
  37. "&np:Item_Number="+result.PartNum +
  38. "&np:Description="+result.Desc +
  39. "&np:Cost="+result.Cost;
  40. var w = window.open();
  41. w.location = url;
  42. return "<html></html>";
  43. }
  44. var wnd = top.aras.getMainWindow();
  45. wnd = wnd === top ? wnd.main : top;
  46. wnd.ArasModules.Dialog.show(“iframe”, param).promise.then(callback);
  47. Save, Unlock, and Close
  48. Edit the My Report_SetDefaults Method Item.
  49. Set the method code as shown:
  50. var fields = [“PartNumber”, “Description”, “Cost”];

    var values = ["%", "%","%"];

    for (var i = 0; i < fields.length; i++){

    // currentField = <FieldID> + “span”

    var currentFieldID = getFieldByName(fields[i]).id;

    // currentField = <Actual field ID>

    currentFieldID =

    currentFieldID.substring(0,currentFieldID.indexOf(‘s’));

    var currentField = document.getElementById(currentFieldID);

    currentField.value = values[i];

    }

  51. Save, unlock, and close.
  52. Navigate to the Administration->Reports off the Main Tree.
  53. Open a new Report Item.
  54. Set the Report Item properties as follows:
    • Name = My Report (this can be anything you want).
    • Type = Generic, ItemType, depending on when you want the Report to appear on the Report menu; Generic always, ItemType only when that ItemType is selected off the Main Tree.
    • Location = Client; this is required because the My Report_OpenDialog Method returns an HTML page with JavaScript that needs to be parsed and Client-side Report only writes the transformed page to the browser window and thus the JavaScript is not parsed.
    • Target = None; the windows will be created by My Report_OpenDialog.
    • Method = My Report_OpenDialog
    • Report Query = Leave blank; it is currently not used for this purpose

The Report Item should now appear on the Report menu and when selected the User Input Dialog should open. When the user clicks Submit the user input is mapped as a query_string and the actual Report is requested from the Report Server via the RSGateway.

If you want to add validation, add this either in My Report_onClick or in MyReport_OpenDialog, after the modal dialog is returned.

You need a dialog to present a set of Reporting Services-based Reports to choose from for the selected Item.

A Client Method based Report is used to present a Form to get the Report choice. The user selection is mapped to a query_string for the Report Server request via the RSGatwway.aspx page. This is similar to recipe 8.1 User Input Form but in this case, we do want the ID for the selected Item to be passed as a Named Parameter on the query_string.

  1. Login to Aras Innovator as admin.
  2. Navigate to the Administration->Lists off the Main Tree.
  3. Open a new List Item
  4. Set the List Item properties as follows:
    1. Name = ReportChooserOptions
    2. Add values with Labels and Values that match the names of your Reports as deployed to the Report Server.
  5. Save, unlock, and close
  6. Navigate to the Administration->Forms off the Main Tree.
  7. Open a new Form Item.
  8. Set the Form Item properties as follows:
    1. Name = Report Chooser (this can be any name you want)
    2. Add a form event that fires onLoad
    3. Name the Method ‘ReportChooser_onLoad’ (this can be anything you want)

    4. Add a new Radio Button List:
    5. Name this field ‘rdio1’

    6. Add a Button field with a label Submit:
    7. Create a Field Event that fires onClick.

      Name the Method ‘ReportChooser_OnClick’ (this can be anything you want).

    8. Save, unlock, and close.
  9. Navigate to the Administration->Methods off the Main Tree.
  10. Edit the ReportChooser_OnClick Method Item.
  11. Set the method code as shown:
  12. var inputOptions = document.getElementsByTagName(“input”);

    var retVal = [];

    for (var i = 0; i < inputOptions.length; i++){

    if (inputOptions[i].className != “arasCheckboxOrRadio”){

    continue;

    }

    if (inputOptions[i].checked === true){

    retVal[‘reportSelected’] = inputOptions[i].value;

    parent.args.dialog.result= retVal;

    }

    }

    parent.args.dialog.close();

  13. Save, unlock, and close.
  14. Create another Method Item (‘ReportChooser_OpenDialog’), this can be called whatever you want).
  15. Set the method code as shown:
    1. The URL query strings (“&np:”) should reference the parameter as defined in the report.
    2. var inn = this.getInnovator();
      var itemIDs = typeof(thisItem)!=="undefined” ? thisItem.getID() : aras.getMainWindow().main.work.grid.getSelectedItemIds(',’).split(',’)[0];
      var ReportInputForm = inn.newItem(“Form”, “get”);
      ReportInputForm.setAttribute(“select”, “id, width, height”);
      ReportInputForm.setProperty(“keyed_name”, “ReportChooser”);
      ReportInputForm = ReportInputForm.apply();
      var param = 
      {
       title: “ReportChooser”,
       formId: ReportInputForm.getID(),
       isEditMode : “1",
       aras : aras,
       opener : window,
       innovator : inn,
       item : this,
       dialogHeight: ReportInputForm.getProperty(‘height’,'800'),
       dialogWidth: ReportInputForm.getProperty(‘width’,'600'),
       content: ‘ShowFormAsADialog.html’
      }
      function callback(dialogWrapper)
      {
       var result = dialogWrapper.result;
       if (!result || !result[‘reportSelected’]){ return; }
       var test=0;
       var url = aras.getServerBaseURL() +
       “RSGateway.aspx?irs:Report=" + result[‘reportSelected’] +
       "&np:id=" + itemIDs; // and the Item ID.
       var w = top.window.open();
       w.location = url;
       return "<html></html>";
      }
      var wnd = aras.getMainWindow();
      wnd = wnd === top ? wnd.main : top;
      wnd.ArasModules.Dialog.show(“iframe”, param).promise.then(callback);
  16. Save, Unlock, and Close
  17. Edit the ReportChooser_onLoad Method Item.
  18. Set the method code as shown.
    1. var radioButtonSpan = getFieldByName(‘rdio1') uses the name of the radio button field as defined on the ReportChooser Form Item.
    2. var radioButtonSpan = getFieldByName(‘rdio1');

      var sysValueSpan = radioButtonSpan.getElementsByClassName(“sys_f_value”);

      if (sysValueSpan.length != 1){

      return;

      }

      sysValueSpan = sysValueSpan[0];

      var inn = this.params.thisItem.getInnovator();

      var reports = inn.newItem(“List”, “get”);

      reports.setAttribute(“levels”, “2");

      reports.setProperty(“keyed_name”, “ReportChooserOptions”);

      reports = reports.apply();

      var reportRel;

      if (reports.IsError() || reports.getItemCount > 1){

      return false;

      }

      else{

      reportRel = reports.getRelationships(“Value”);

      }

      for (var i = 0; i < reportRel.getItemCount(); i++){

      var value = reportRel.getItemByIndex(i);

      var valueLabel = value.getProperty(“label”, "");

      var reportButtonSpan = document.createElement(“span”);

      reportButtonSpan.setAttribute(“id”, “MyRadio”);

      reportButtonSpan.setAttribute(“name”, valueLabel);

      reportButtonSpan.setAttribute(“style”, “position:relative;display:block;");

      var radioInput = document.createElement(“input”);

      radioInput.setAttribute(“type”, “radio”);

      radioInput.setAttribute(“value”, valueLabel);

      radioInput.setAttribute(“name”, “ReportOptions”);

      radioInput.setAttribute(“class”, “arasCheckboxOrRadio”);

      var reportLabel = document.createElement(“label”);

      reportLabel.setAttribute(“for”, “MyRadio_id”);

      reportButtonSpan.appendChild(radioInput);

      reportButtonSpan.appendChild(radioInput);

      reportButtonSpan.appendChild(reportLabel);

      reportButtonSpan.appendChild(document.createTextNode(valueLabel));

      sysValueSpan.appendChild(reportButtonSpan);

      }

  19. Save, unlock, and close.
  20. Navigate to the Administration->Reports off the Main Tree.
  21. Open a new Report Item.
  22. Set the Report Item properties as follows:
    1. Name = Report Chooser (this can be anything you want).
    2. Type = Item (You do not need the report_query template when prompted).
    3. Location = Client; this is required because the ReportChooser_OpenDialog Method returns an HTML page with JavaScript that needs to be parsed. The Client-side Report only writes the transformed page to the browser window and thus the JavaScript is not parsed.
    4. Target = None; the windows will be created by ReportChooser_OpenDialog.
    5. Method = ReportChooser_OpenDialog
    6. Report Query = Leave blank; it is currently not used for this purpose
  23. Save, unlock, and close the Report.
  24. Navigate to the Administration->ItemTypes off the Main Tree.
  25. Search for the ItemType for this Report.
  26. Edit the ItemType and select the Reports Tab.
  27. Add an Existing related Item and select this Report.
  28. Save, unlock, and close the ItemType.

The Report should now appear on the Report menu when the Item is selected. When the user clicks Submit the selected Report, the actual Report is requested from the Report Server via the RSGateway.

The ID for the selected Item is automatically passed as a Named Parameter np:id so you must name your Named Parameter in the SQL query with lowercase id also.

You need user input for XSLT based Reports.

Use a Generic Report called from a client Method so that user input can be collected for the query.

This section describes the steps for building the User Input Report. This is an example and there are alternative ways to implement the user interface, but this does illustrate a way to dynamically run a Report.

In this example, we use a very simple Report to get one input from the user, which is the Part Number for the item_number property for the Part ItemType to dynamically build the AML query for our Report.

The following are the steps for building an Interactive Report:

  1. Create a Generic Report as a template.
    1. Set the Report properties as follows:
    2. Name = My Report (this can be any name you want)

      Type = Generic

      Location = Server

      Target = Window

    3. Construct an AML query and write the Report as usual.
    4. Once the Report is written the AML query is no longer required because the Report acts as a template and the AML query is provided from the user input interactively so remove the Report Query AML from the Report item. But you may want to use the AML query string as the starting point for building the query in the Method coming up next.
  2. Create a client-side Method (named “My Report” for this example) that will:
    1. Get the user input for the query, which is a modal dialog for this example.
    2. Construct the actual AML query based on the user input. Use the AML query from the Report you created as the starting point. We replace hard-coded search criteria in the AML with variables in our Method.
    3. Create an XML document to hold the AML query.
    4. Get the Report item.
    5. Run the Report passing the query XML document as the query criteria.
  3. Create an Action to call the Method. Set the Action properties as follows:
  4. Type = Generic

    Location = Client

    Target = None

    Method = My Report

    Name = My Report

    This provides the logic to get user input and to invoke the Report from an Action menu choice. The following is client-side Method code to run the Interactive Report:

    // The Report is run as a Generic Report so we can pass our own AML query for the Report.
    // Get the query criteria from the user via a modal dialog.
    var params = 
    {
     aras:aras, innovator: this.getInnovator(), 
     dialogHeight:227, dialogWidth:350,
     content: ‘ReportTool/UserDialogs/MyReport.html’
    };
    function callback(dialogWrapper)
    {
     var result = dialogWrapper.result;
     if (!result){ return; }
     // Create a query Item to hold the AML query for the Report.
     // The ItemType Part is an example and you can set this as required.
     var qry = aras.IomInnovator.newItem(‘Part’,'get’);
     // The user input from the modal dialog is serialized the into a string.
     // The format for the serialized string is | delimited for the list of properties
     // for constructing the query and each property is a name/value pair : delimited.
     var params = result.split('|');
     for (var i=0; i<params.length; ++i)
     {
     var param = params[i].split(':');
     qry.setProperty(param[0], param[1]);
     }
     // Get the Report item by name.
     var reportQry = aras.IomInnovator.newItem(‘Report’,'get’);
     reportQry.setProperty(‘name’, ‘My Report’)
     reportQry.setAttribute(‘select’,
     ‘name,description,report_query,target,type,xsl_stylesheet,location,’ +
     ‘method(name,method_type,method_code,runas_user,runas_pwd)’);
     var report = reportQry.apply();
     // Run the report passing the query Item as the query criteria for the Report.
     // The runReport function is part of the client Toolkit API,
     // which expects node object not IOM Item objects.
     aras.runReport(report.node, '', qry.node);
    }
    var wnd = aras.getMainWindow();
    wnd = wnd === top ? wnd.main : top;
    wnd.ArasModules.Dialog.show(“iframe”, param).promise.then(callback);
  5. Create the HTML page that captures the user’s input for the Report. In the sample Method code above, you notice the call to open the modal dialog and load it with the ReportDialogs/MyReport.html page. This is the relative URL to the file from the Client/scripts folder for which the Methods on the server side are invoked.
  6. Note
    If the folder Client/scripts/ReportTool/UserDialogs does not exist create it. The folder name can be anything you want; basically, we are simply creating a location to put the HTML files for the Report dialogs.

    The following is the sample HTML for the MyReport.html page: <html> <style type="text/css"> body { background-color:#d4d0c8; }.header { background-color:#CCCCFF; font-family:helvetica; font-weight:bold; font-size:16pt; font-style: italic;color:#000000; border-width:1px; border-style:inset; padding:8px; }.buttons { background-color:#d4d0c8; border-width:2px; border-style:groove; padding:10px; } td { font-family:helvetica; font-weight:bold;font-size:8pt; } </style><script>var args = window.frameElement ? window.frameElement.dialogArguments : window.dialogArguments,aras = (args && args.aras) ? args.aras : parent.aras;window.dialogArguments = args;function cancel() {args.dialog.result = '';args.dialog.close(); } function apply(form) {args.dialog.result = '';// Serialize the field values into a string.// Delimit the fields with the | character// and delimit the property name/value with the : character.// i.e. prop-name:value|prop-name:value for (var i=0; i<form.elements.length; ++i) { var field = form.elements[i]; if (field.type == ‘text’) { if (field.value) { if (args.dialog.result)args.dialog.result+= '|';args.dialog.result+= field.name + ':' + field.value } } }args.dialog.close(); } onload = function() {document.body.scroll = ‘no'; } </script> <body> <form> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr height="60"> <td class="header” colspan="2"> My Report </td> </tr> <tr> <td align="right” style="padding:20px 10px 0px 0px;" nowrap> Description: </td> <td style="padding:20px 00px 0px 0px;"><input type="text” name="part_desc"></td> </tr> <tr> <td align="right” style="padding:4px 10px 20px 0px;" nowrap> Cost: </td> <td style="padding:4px 0px 0px 0px;"><input type="text” name="part_cost"></td> </tr> <tr> <td align="center” class="buttons” colspan="2"> <input type="button” value="OK” onclick="apply(this.form)"> <input type="button” value="Cancel” onclick="cancel()"> </td> </tr> </form> </body></html>

  7. You should now be able to click on My Report in the Action menu and interactively run the Report.