Merlin – Adding an option in a python/wbl report template

Report template options are saved in the /Contents/info.plist within a Merlin‘s report template package and shown in the order they are defined. Therefor, should you want to add another option for your custom report:

  • You open the info.plist as found in your report template package under /Contents
  • Check the dictionaries defined for the key PWReportParameters
  • And define your own dict in the position you would like it to be shown

Note: Use existing options as reference on how to define checkboxes, lists, or text entry fields

Some examples:

1. You have created a copy of the existing XSLT report  and want to add an option.

Your workflow

Proceed as explained here

2. You have created (as explained here) a copy of the existing Cost Distribution report which is a python/wbl report template and want to add an option to disable the “Base Cost” column in the outputted table.

Your workflow

  • Open the info.plist as found in your report template package under /Contents
  • Copy the dict definition for another checkbox option (for example this for withProjectImage)
  • And paste
  • Edit the strings for key and title in the pasted dict.
<dict>
<key>key</key>
<string>withBaseCosts</string>
<key>title</key>
<string>Base Costs</string>
<key>valueClass</key>
<string>NSNumber</string>
<key>style</key>
<string>bool</string>
<key>defaultValueString</key>
<string>1</string>
</dict>

Note: A defaultValueString of 0 defines it off per default. Should you like to have this column outputted, but to be able to switch it off over the options, just enter here 1.

 

  • Save your changes
  • Open the python script as found under /Contents/Resources in a text editor
  • Define your method in the python class
    self.withBaseCosts  = 0

  • Save your changes
  • Open the wbl file as found under /Contents/Resources in a text editor 
  • Locate the line for the “Base Cost” column title
    <th><wbl:String value="Base Cost" localize=YES /></th>
  • Do a test for the value of withBaseCosts and allow it to be shown only if checked:
    <wbl:Conditional condition=withBaseCosts>
         <th><wbl:String value="Base Cost" localize=YES /></th>
    </wbl:Conditional>
  • Save your changes (make sure that all three files are saved: Info.plist, the py and wbl files)
  • Restart Merlin if it is already running
  • Open your project
  • Call File > New Report…  and select your thus changed report
  • See Base Costs being outputted per default, but you can disable them in the options

Note: The outputted table on the report is not yet correct. That it is because we forgot to put all outputs of basecosts in conditionals.

So:

  • Open once again the wbl file
  • Find further base costs outputs in the report… To be more specific search for the following two lines:
    1. <td><wbl:String value=iterIntervalBaseCost formatter=project.currencyFormatter/></td>
    2. <td><wbl:String value=project.baseCostDeep formatter=project.currencyFormatter valueWhenEmpty=0/></td>
  • Put them in conditionals

  • Save the wbl file
  • Refresh your report or restart Merlin and call the report once again
  • It will hide/show the base cost columns are desired

Adding a property in an existing report

Please see next posts

______

Related Posts:

5 thoughts on “Merlin – Adding an option in a python/wbl report template

  1. Can I use this technique to add a custom column to a report?

    I have a couple custom columns (they are simple text fields) I’ve added to my project file and I’d like to include them in a report format.

    Also, is the python/wbl report template a better solution to this or would it be easier to customize the other report format?

  2. I am intending to write in the next post, how to find the names of the properties to use when needing to insert something which is not already mentioned in a template… but custom fields are yet again something different.

    I am not expecting you can report custom fields over XSLT report templates. Because this kind of report is based on a Merlin XML file created out of the current project, and custom fields are not exported in Merlin XMLs….

    So I would have to do some research on this first for the python reports. Hopefully I can find a way to output them.

    Best regards, Vicky

  3. You can output the user defined data over ‘userInfo’

    So If having 2 user defined fields: add1 and add2
    And want to output them in the overdues as shown in a report based on the classic report…

    You add in the iteration area…

    <td><wbl:String value=iterItem.title/></td>
    <td><wbl:String value=iterItem.parentActivity.title/> </td>

    The following two rows…
    <td><wbl:String value=iterItem.userInfo.add1/> </td>
    <td><wbl:String value=iterItem.userInfo.add2/> </td>

    In case there is a way to create the report without “knowing” how those custom fields are really called… I will let you know.

    Best regards, Vicky

  4. Thanks Vicky. I appreciate the response.

    I’m going to try your suggestion in the next day or so. I’m sure I’ll have other issues that come up.

    Believe it or not I’m anxiously awaiting your blog posts in this series. Keep up the good (and useful) work.

  5. Pingback: Merlin – Do a little bit of magic in Merlin reports – part XXV | MacPM

Comments are closed.