diff --git a/perllib/Open311/Endpoint/Integration/Echo.pm b/perllib/Open311/Endpoint/Integration/Echo.pm index 7d0e459dc..9c7223725 100644 --- a/perllib/Open311/Endpoint/Integration/Echo.pm +++ b/perllib/Open311/Endpoint/Integration/Echo.pm @@ -332,14 +332,16 @@ sub post_service_request { # Look up extra data fields my $event_type = $integ->GetEventType($request->{event_type}); - foreach my $type (@{$event_type->{Datatypes}->{ExtensibleDatatype}}) { + my $data = force_arrayref($event_type->{Datatypes}, 'ExtensibleDatatype'); + foreach my $type (@$data) { my $row = { id => $type->{Id} }; my $value = $self->check_for_data_value($type->{Name}, $args, $request); my %extra; my $extra_count = 0; if ($type->{ChildDatatypes}) { - foreach (@{$type->{ChildDatatypes}{ExtensibleDatatype}}) { + my $moredata = force_arrayref($type->{ChildDatatypes}, 'ExtensibleDatatype'); + foreach (@$moredata) { my $subrow = { id => $_->{Id} }; my $value = $self->check_for_data_value($_->{Name}, $args, $request, $type->{Name}); if (defined $value) { @@ -495,4 +497,13 @@ used as part of a Multi integration. sub get_service_request_updates { } +sub force_arrayref { + my ($res, $key) = @_; + return [] unless $res; + my $data = $res->{$key}; + return [] unless $data; + $data = [ $data ] unless ref $data eq 'ARRAY'; + return $data; +} + 1; diff --git a/perllib/Open311/Endpoint/Integration/UK/Brent/Echo.pm b/perllib/Open311/Endpoint/Integration/UK/Brent/Echo.pm index c826eb4b1..cb4d48150 100644 --- a/perllib/Open311/Endpoint/Integration/UK/Brent/Echo.pm +++ b/perllib/Open311/Endpoint/Integration/UK/Brent/Echo.pm @@ -60,7 +60,7 @@ around post_service_request_update => sub { my $event_type = $integ->GetEventType($event->{EventTypeId}); my $state_id = $event->{EventStateId}; - my $states = force_arrayref($event_type->{Workflow}->{States}, 'State'); + my $states = Open311::Endpoint::Integration::Echo::force_arrayref($event_type->{Workflow}->{States}, 'State'); my $data; foreach (@$states) { my $core = $_->{CoreState}; @@ -80,13 +80,4 @@ around post_service_request_update => sub { return $class->$orig($args); }; -sub force_arrayref { - my ($res, $key) = @_; - return [] unless $res; - my $data = $res->{$key}; - return [] unless $data; - $data = [ $data ] unless ref $data eq 'ARRAY'; - return $data; -} - 1;