Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Please advise - SS_Report - user selected parameters not working


Go to End


1165 Views

Avatar
MJA

Community Member, 21 Posts

10 September 2014 at 3:54am

Hello people, this one has been driving my mad all afternoon

I am trying to set up a custom report with some selection criteria - nothing I haven't done a hundred times before (code fragment below)

The problem is that the selected parameter array is not being passed into sourceRecords()
Or, to be more accurate, an empty array is being passed regardless of what is selected in the dropdown field
This results is that the report is return all records, not just the ones for the selected client

Also, the selection is not being preserved after clicking the Filter button
That is, when the report screen refreshes the dropdown field has returned to the default value

The code, as far as i can see, is identical to what I have used in all my other ss reports, all of which work correctly so this makes no sense to me

Can anyone out there explain why this is not working?

(In case it is relevant - the site is running under SS 3.1.3)

Thanks in advance for any help you can offer


	class powerbankOrderExport extends SS_Report {
	
		public function parameterFields() {
			return new FieldList (
				DropdownField::create('Client')->setTitle('Client')
					->setSource (
						array (0 => '[ all ]') +
						powerbankClient::get()->map('ID', 'Name')->toArray()
					)
			);
		}
		
		public function sourceRecords($params, $sort, $limit) {
			$where = 'powerbankOrderLine.ProductID > 0 and powerbankOrderLine.LogoID > 0';
			if ((int) $params['Client'] > 0)
				$where .= ' and powerbankOrder.ClientID = ' . (int) $params['Client'];
			
			$orderLines = powerbankOrderLine::get()
				->leftJoin	('powerbankOrder', 'powerbankOrder.ID = powerbankOrderLine.OrderID')
				->leftJoin	('powerbankClient', 'powerbankClient.ID = powerbankOrder.ClientID')
				->where		($where)
				->sort		('powerbankClient.Name, powerbankOrder.OrderRef, powerbankOrder.PONumber, powerbankOrderLine.ID');
			
			return $orderLines;
		}
	
	}	// end class powerbankOrderExport