Accessing the current customer for a report

I have been asked to generate what is functionally a customer statement that extends over multiple accounting periods.  You cannot use Reporting|Debtors to do this - it can only report reanactions is a single accounting period. [The logic appears to be 'find the Opening balance transaction prior to the specified statement date and report all transactions bwetween that and the specified statement date.]

No problem - I have written a report to do what is required.  However to run the report, one has to enter the id number of the required customer.

Is there any way to get at the current customer id?  I have tried both a macro (not supported in the report criteria entry), and an  [openvpms:get(., "customer.entity.id")] expression (rejected as does not look like a number).

It would be really nice if:

  1. one could enter something short as a synonym for the current customer's id (eg $cid); or
  2. macros were supported in the report criteria fields (so I could enter @cid have the macro return the results of the expression  [openvpms:get(., "customer.entity.id")];
  3. I could set a varible in the report to the expression  [openvpms:get(., "customer.entity.id")] so as the get the current customer id without the user having to prompt for it.

Regards, im G

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Accessing the current customer for a report

The expression you are after is:

  $customer.id

This works as $customer is a party.customerperson, and id is a node of party.customerperson.

So you could define a macro @cid with the above expression, and enter this in a report parameter. The macro will be expanded when you press Enter.

It would be possible change the report framework enable access to the $customer and $patient variables from within xpath expressions, but there is a bit of refactoring involved.

Re: Accessing the current customer for a report

Tim A - thanks for this. I created the @cid macro and it works as expected in places where macros are supported.  However if I use it in CustomerId field in the Report Criteria window, then it will not expand.

Then - ahah - I have the id field typed as a number. If I change it to a string - it works!!

Now all I have to do is find out where the size of the string fields is set for the Report criteria window so that I can decrease it to one line so it looks better. [I have yet to come across a case where the data being entered as a report criteria is more than one line, so I see no downside in decreasing the size (unlike note etc text where almost always the text will be longer than one line.]

I have added to the CSH documentation to provide the above info (and I also added the date shortcut tricks) - see http://www.openvpms.org/documentation/csh/1.7/reporting/report/run

Re: Accessing the current customer for a report

Yep - macros only work in string fields.

The report parameters can't have a length defined, so a text area is used to edit them. This is annoying if you just want single line entry, but necessary if you want to enter multi-line text. An alternative would be to provide a component that supports both i.e it displays as single line by default, but clicking a button pops up a multi-line editor.

-Tim A

Re: Accessing the current customer for a report

Tim  - can't you just set the initial size of the field to be small?  You can see below that I can manually resize it to one line deep. Regards, Tim G

Re: Accessing the current customer for a report

That resize feature is browser specific. Its available in Firefox, Chrome and Safari.

Firefox lets you resize smaller than the initial size, whereas Chrome and Safari don't appear to. I don't think its available in IE, and I'm not sure about other browsers.

Re: Accessing the current customer for a report

Ahah - having just had a quick play with Chrome, I see what you mean.

So the underlying problem is that iReport does not distinguish between single and multi-line string parameters and hence you have to allow for multi-line. Given that the problems is essentially cosmetic - ie the Report Criteria window would like nicer if it used single line strings where possible, we don't have to solve this. However, if we did want to, then the following approaches are possible:

  1. your idea of  'press a button to switch'
  2. have a style switch that says whether the report criteria strings should use single or multi-line boxes (but this would be a global switch which might be a problem)
  3. introduce a switch based on the parameter name - if the parameter name (not the prompt text) starts m_ (eg m_address) then a multi-line field is used, else a single line of say 35 characters is used

I am confident that the last suggestion would have no effect on current users (I know of no reports that require an multi-line input (like an address)), but it would allow for the use of multi-line input if ever required.

Regards, Tim G

Re: Accessing the current customer for a report

I'm not too keen on magic naming conventions.

On closer inspection of the Jasper Reports JRParameter class, it can have its own properties defined. These are simple key/value pairs, so there is potential for adding meta-data like:

  • length 10
  • multiline true

that can be intepreted by the Report Parameters dialog.

These can be set in iReport. I don't know of any similar facility OpenOffice, so I'm leaning towards the button to switch between single and multiline editing option.

Syndicate content