Manage Large Data Sets for Notification Routing

Hi All,

I have a form that will go to 30 different email addresses based on the result of the postcode field.

There are literally hundreds of postcodes. Manually entering them will be arduous. Managing them will be even worse as the form will be replicated many many times over.

Is there a way that the routing of postcodes could be managed in one central file (JSON?) or using the API? A 3rd party plugin?

I’ll keep digging. Thought I’d reach out & see if anyone has any suggestions.

Thanks Wes

You can do that using the gform_notification filter:

Example #8 covers configuring routing. You would incorporate that approach with getting your date from a database or file of some sort, to create your rules from one source, dynamically as the source changes.

Thanks Chris, It’s taken me a while to circle back here.

I am wondering if the notification routing will accept ranges, as I have 16,700 postcodes and that’s a lot of data entry! :slight_smile:

For example we want to send an email to when the postcode fields is in the range of 2000-2012 & an email to when the postcode is in the range of 3047-3059.

Any ideas? Appreciate the help!

No, the routing rules in the form builder for Notifications, or in the code, do not support a range. These are the comparisons which are supported:

  • is
  • is not
  • greater than
  • less than
  • contains
  • starts with
  • ends with

There is no option to say less than AND greater than.

You may need a different approach. Instead of routing, can you use gform_notification to just set the TO email address when the postcode is within your range. It would look more like example 2 here with lots of switch/case statements or if/then statements.

Or, maybe you could store the postcode and the associated email address in a database table or file, and perform a lookup in the gform_notification filter. That way, you would not have a lot of code, and would have a database table with the postcodes and the email addresses, and you would query the database in your code to find the email address that matches your postcode.

Thanks Chris!

This worked out pretty well. Thank you.

I didn’t go down the track of a JSON file, I just put all the rules into the functions.php file and consolidated the postcodes where possible. I think in the future I will get something happening with a JSOn file for easier management, I just didn’t have time for it.

Along with the email notifications being routed, there is a separate notification that is a ‘catch all’ email that goes to the main client (head office). They have now requested that I push a field through to their separate notification that has an additional field that shows which email the first notification was routed too.

Any clues what I might be able to do with this?

Really appreciate your input!

Cheers, Wes

perhaps this ?

For the record, I used this for the routing:

add_filter( ‘gform_notification’, ‘notification_routing’, 33, 3 );
function notification_routing( $notification, $form, $entry ) {
if ( $notification[‘name’] == ‘Admin Notification’ ) {
$notification[‘toType’] = ‘routing’;
$notification[‘routing’] = array(

    array('fieldId' => 12,'operator' => 'contains','value' => '200','email' => ''),
	array('fieldId' => 12,'operator' => 'contains','value' => '221','email' => ''),
	array('fieldId' => 12,'operator' => 'contains','value' => '2581','email' => ''),
	array('fieldId' => 12,'operator' => 'contains','value' => '2582','email' => ''),

etc. etc.