Plugin Sample - Custom Search - Email

Samples and Examples of using the Jiwa 7 framework - including plugins, stand-alone applications and scripts.

Plugin Sample - Custom Search - Email

Postby Scott.Pearce » Mon Apr 28, 2014 1:07 pm

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 9874 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 9874 times




3. Enter the text/code as denoted in the screenshot below.
3.PNG
Enter the code
3.PNG (69.49 KiB) Viewed 9874 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 9874 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 9874 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 9874 times
Attachments
7.2.1 Plugin Custom Search - Email.rar
Plugin for Jiwa v7.1.0.0 and higher
(3.09 KiB) Downloaded 131 times
Plugin Custom Search - Email.rar
Plugin Custom Search - Email
(3.2 KiB) Downloaded 168 times
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Return to Samples and Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron