Page 1 of 1

Plugin Sample - Custom Search - Email

PostPosted: Mon Apr 28, 2014 1:07 pm
by Scott.Pearce
Here is a nice plugin sample that illustrates the creation of custom searches in Jiwa v7 (in Jiwa v6, this would have been done from Search Screen->Manage Breakouts).

Specifically, when performing an search for email (from the Email Maintenance screen, for example) a new search option is added with a title of "Date Sent". The "Date Sent" search option includes the date sent field in the search results. Below are the step by step instructions to create such a plugin. I've also attached an XML export of the plugin so that you can import it into your own databases rather than typing. Let's begin.

1. Log in to Jiwa and go to System Settings->Plugins->Plugin Maintenance.
1.PNG
System Settings->Plugins->Plugin Maintenance
1.PNG (54.14 KiB) Viewed 9884 times




2. Create a new plugin and provide a plugin name, the author, and a brief description as to what the plugin does.
2.PNG
Create a new plugin
2.PNG (20.2 KiB) Viewed 9884 times




3. Enter the text/code as denoted in the screenshot below.
3.PNG
Enter the code
3.PNG (69.49 KiB) Viewed 9884 times


Code: Select all
AddHandler JiwaApplication.Manager.Instance.Search.Showing, AddressOf Search_Showing


Code: Select all
Private Sub Search_Showing(sender As Object, e As System.EventArgs)
      With JiwaApplication.Manager.Instance.Search
         If .CurrentSearchMode = JiwaApplication.JiwaSearch.clsSearch.SearchModes.jswEmailMessages Then
            
            ' Add DateSent to display
            Dim AOption As New JiwaApplication.JiwaSearch.SearchOption
            With AOption
               .Title = "Date Sent"
               .SQLStr = "SELECT RecID, EMailNo, DateSent, EmailFrom, EmailTo, EmailSubject FROM EM_Main "
               .OrderBy = "ORDER BY EMailNo"
                    .AddColumn ("RecID", vbString, "", 0, 1)
                 .AddColumn ("Email No.", vbstring, "", 5, 2)
                 .AddColumn ("Date Sent",  vbDate, "", 15,3)
                 .AddColumn ("From", vbString, "", 20, 4)
                 .AddColumn ("To", vbString, "", 25, 5)
                 .AddColumn ("Subject", vbString, "", 35, 6)
            End With
               
            .Options.Add(AOption)                     
         End If
      End With
   End Sub      


The first code fragment hooks in to the "show" event of the search screen. It tells the system to call a function titled "Search_Showing" whenever the search screen is displayed.

The second code fragment is the "Search_Showing" function itself. This function first looks at the type of search, and if it is an Email search, it defines and adds a new search option called "Date Sent" to the search object.



4. Click the compile button to make sure there are no errors in our code.
4.PNG
Compile
4.PNG (64.83 KiB) Viewed 9884 times




5. If compilation was OK, you should now enable the plugin by ticking the "Enabled" checkbox at the top right of the Plugin Maintenance screen.
5.PNG
Enable the plugin
5.PNG (25.96 KiB) Viewed 9884 times




6. You must now exit Jiwa and re-login so that our new plugin will be active (all plugins are loaded by Jiwa at login time).


7. To test our plugin, go to "System Settings->Email->Email Maintenance". Click on "Search". In the "Select a Query" pull-down you should see a new search option titled "Date Sent" - select this and ensure the search executes without error, and that a search result can be selected, resulting in the appropriate Email Maintenance record being read.
6.PNG
The plugin working
6.PNG (48.46 KiB) Viewed 9884 times