Advanced Techniques - Save a Microsoft Exchange email in a data group
This workshop demonstrates step-by-step how an email from Microsoft Exchange
can be mapped and saved to a data record in a portal application.
1. Create connection
If you have not set up a connection to Microsoft Exchange, create one with the
Connector for Microsoft Exchange
to begin with. A guide to creating a connection is available here.
2. Import Microsoft Exchange applications
If you have not already imported
the "Exchange - E-Mail" application, please do so now. Click
here
if you do not know where the import packet is or you require more information.
3. Modify Exchange applications
Open the "Exchange - E-Mail" application in the
Applications module.
Open the "_tblPreview" page in the "Messages" data group. Create a
button
on the page and provide it with the title "Save email".
function triggerWorkflow(p_strRecId)
{
triggerUserWorkflowEvent('911F44EE227AE9D9D441C3CE57E10728A457F6E9', {qs_id: p_strRecId});
return true;
}
With this script a process (we will create this later on) is triggered. The ID
of the email is transferred to the process as a request parameter using "p_strRecId".
Close the script editor by clicking on "OK".
On the Script tab,
click on "Add script" and select the
event "onclick". In the "Function" field insert the function call
triggerWorkflow('$drRecord.getRecId()')
Confirm all dialogs by clicking on "OK" and then save the application.
4. Target application
The process, which we will create in the next chapter, can save the email
in a data group of any existing or new application. To do this, this data group
requires a data field
with the "File" data type.
Create such a data field
in your target application. The new field can, for example, be incorporated
into a table that displays data records from the respective data group.
Remove any existing process elements and create a new
Generic event handler.
Select the class "UserWorkflowEventHandler" in the properties dialog
and use the GUID, which you used in the JavaScript function "triggerWorkflow()"
as the eventGuid (in our example 911F44EE227AE9D9D441C3CE57E10728A457F6E9).
Confirm your entries with "OK".
Create a Groovy script action
and connect it to the Generic event handler. Insert the following script there:
In the SQL commands SELECT and INSERT, please replace the GUID shown with
the GUID of the data group from the target application.
The names can be obtained very simply via the
Application structure
once you have selected your application. Furthermore you need to replace the
GUID "F86BD249C2E9D9090109F3BA3B568DA683C86D05" in the last script line
with the GUID of your file data field from the
target application.
In the first step, the desired email will be saved in the cache so that
it can then be added to the data group. Afterwards, a new data record
is generated in the data group with the SQL statement "INSERT". The email's
subject is used as the title for the new entry in the
target application.
Please note that special characters in the subject of an email
may cause errors during saving.
With the help of the class "FileUCHelper" the cached email object is added
to the record just created in the last step.
The following parameters need to be added here:
g_context: The current processing context. g_context can be used as a constant.
fileMail: The file object of the cached email.
GUID: The GUID of the file data field where the email will be stored.
<File name>.eml: The new file name of the stored file object.
true/false: Should a data group event handler, which is defined for the
target data group, react to the addition of the file?
As the name of the saved email, the current time is used in our example.
Other filenames such as subject (without special characters), customer number
or ID are also possible, and can be selected individually.
Save and publish the process, and open the email application in the browser.
Select a message to be archived, and click on the "Save email" button.
Once the process has been performed, you will find the email in your target application.