Table Of Contents
 

UDI - How to: Dynamic Includes

Author : Peter Coppinger Email : peter@digital-crew.com

Dynamic includes are a powerful feature of UDI that allow you to perform custom processing before and after the database gets update with an INSERT, UPDATE or DELETE action.

For this full list of Dynamic Include options, see UDI Attributes.

Why Dynamic Includes are Useful

Here are some examples of what you can do with this ability:

  • Perform custom extra validation of form data before updating/inserting into the database.
  • Prevent records being prevented accidentally.
  • Create, update or delete extra database or file objects associated with this object.
  • Create required directory structures.
  • Copy or resize images that have uploaded.
  • Perform extra processing of uploaded resources.
  • Update the database with some extra details for the newly inserted record.

Real world examples from Digital Crew projects:

  • Create several different sized thumbnails.
  • Prevent the user deleting a page that has attached sub-pages in TeamworkCMS.
  • Extracting all the text from an uploaded word file for indexing.

Debugging Dynamic Includes

Make sure to turn the UDI debugging option on when testing your dynamic includes. Use the UDI showdebug="yes" option to display the debugging option. With debugging enabled, you will be able to display the iframe that performs the updating by clicking the "Show Debug" option at the bottom of the edit window.

If you have an error in your include file, scroll to the bottom of the iframe to see the error.

The Include File Path

when you say something like includeOnInsertOrUpdateOrDelete="udi_onInsertOrUpdateOrDelete.cfm", the file udi_onInsertOrUpdateOrDelete.cfm should be in the root folder in this example.

We recommend you make a "UDIActions" folder within your project and put your UDI dynamic include files in there.
For example:

includeOnInsertOrUpdateOrDelete="pages/UDIActions/udi_onInsertOrUpdateOrDelete.cfm". UDI will now try and include the file "pages/UDIActions/udi_onInsertOrUpdateOrDelete.cfm" - in this example, the "pages" folder should be in the root of your project.

Tips

  1. To see all the fields that are available, just put <cfdump var="#FORM#"><cfabort> at the top of the include file.
  2. It is easier to use the general purpose includeBeforeInsertOrUpdateOrDelete and includeOnInsertOrUpdateOrDelete options than the other more specific options such as includeOnUpdate. You can then something like <cfif FORM.updateType EQ "INSERT"> in you dynamic include to perform processing based on the update type.
  3. We recommend using a naming convension for your dynamic include such as "b4InsertOrUpdateOrDelete_user.cfm" or "onInsertOrUpdateOrDelete_user.cfm".