Epicor introduced the Pre-SQL hook as a new feature for the DynaChange Rule in version 12.17. This feature extends the reach of a DynaChange Rule to insert business logic, including modifying the SQL statement itself, before the statement executes. This can be a slippery slope. P21 is a complex application, and tinkering too much can have unintended consequences. Having said that, this feature does open a new range of possibilities for companies on Prophet 21.
Watch Now: DynaChange Rule – Pre-SQL Hooks in Prophet 21
Setting up a Pre-SQL hook is not necessarily difficult, but there are a few steps that you need to follow if you hope to have success. Unfortunately, there is just not a lot of documentation on the subject right now. Hopefully this guide will help you get on the right track.
Find the SQL Statement…
- Use SQL Profiler to set up a trace on your database. This is a required step. Part of setting up the hook is knowing the id or name of the SQL statement you are trying to modify. The often look like
- With the trace running, run Prophet 21 to make it fire the SQL statement you want to modify. One this happens, you can stop the trace.
- Start looking through the trace to try and find the SQL statement you want to modify. I would recommend copying the statement over into Management Studio and running it to be sure that it is the right one.
- Once identified, work out your plan for how you want to modify it. I highly recommend only using this feature to modify WHERE and ORDER BY clauses. Anything more can have an unintended effect on P21. Be very careful about what you modify and to what degree.
Write the DynaChange Rule…
- Set up a blank DynaChange rule in Visual Studio, or whatever other editor you use. There is a template shown in the video.
- Next, declare a string variable, and set it to:
- There are several ways to affect the SQL statement from here. In the video, I get the integer value of the point in the statement I want to affect. Then I use an insert to put in the additional code. Any string manipulation you like should work just fine.
- Finally, pass the new SQL statement back to Prophet 21 via
Set up the New DynaChange Rule…
- Once you are happy with the code, build the DLL and copy it over to your DynaChange Rules Folder.
- Open Prophet 21, and then open the DynaChange Rules Organizer.
- Then click the
Create Pre-SQL rulebutton, a dialog box will open.
- In the dialog, enter the
DS d_ds_some_name_goes_herename of the SQL statement you modified.
- Next, select the name of the business rule using the drop down box.
- Leave the run type alone. It is always Synchronous.
- Click ok, save the rule, and then test it out. Hopefully everything worked out OK.
Pre-SQL hooks are a powerful feature in Prophet 21. They can produce unexpected results if you are not super-careful, so test in Play until you are confident the rule is working right. I hope you have lots of luck developing your next Pre-SQL hook and make P21 work even better for your company!
Read More about Prophet 21 on freeingERP.com