November is an exciting month here at Geocortex, as we’re thrilled to announce the release of the on-premises version of Geocortex Workflow!
To commemorate this release, we thought it would be very fitting to have our next few rounds of Geocortex Tech Tips focus on our Workflow technology.
One of the key new features that the on-premises version supports is a new type of workflow called “server workflow”. These workflows execute on the server as a web service, compared to normal workflows that execute in the end user’s web browser, meaning that server workflows ultimately have access to resources that otherwise couldn’t be reached from a web browser.
An example of one of these resources – and where we thought we’d focus this week’s Geocortex Tech Tip on – is how to send an email with an attachment using this new server workflow. These emails can include multiple recipients including both CC’s, BCC’s. Check out the video below to learn how it works!
“Hi, I’m Noah and I work on the Products team. Today we’re going to learn how to send an email with the on-premise version of Geocortex Workflow 5. Let’s take a look!
So, today we’re going to learn how to create a server workflow that can send an email to a user with an attachment.
Right in front of me I have a client workflow which asks the workflow runner for a username and an email address and then runs a server workflow which is going to send our email for us.
Over here I have the server work form running. Right now what this server work flow does is it gets the workflow inputs with that username and email address, and it reads a data file for us. The data file is just some csv data that we’re going to put in our email as an attachment.
The first thing we want to do is create the attachment to put on to the email. The content of the attachment is going to be our file. It’s going to be the bytes from Read File Bytes. Our content type is going to be text/csv since we’re reading since we have a csv file, and our file name is going to be data.csv. This produces an attachment object and as you can see here, ‘This object should be passed to the Send Email activity’, so that is what we are going to sue next.
The send email activity has a To, a From, a CC, and a BCC, and the To, the CC and the BCC can all take either one value or an array of multiple values. For the value of To, I’m going to just use one value which came from our client workflow; it is going to be the username. Let’s look for the user’s email. It’s called email.
Now From, let’s use my own email. For CC, let’s CC a couple people just to show how the array works. I’m going to create a new array with the equal sign and then a square bracket and lets CC ‘firstname.lastname@example.org’ and ‘anotherDeveloper@latitudegeo.com’. You could add as many emails as you like to the CC, the BCC, or the To fields on the send email activity. Let’s leave the BCC empty. Let’s make our subject ‘Email techtip’. Now the email body can either be an html body or just plain text. Let’s make it some html.
First, let make a header. And let’s make the header say ‘The Data’. Then, let’s make a paragraph and let’s address our user. We’re going to grab the user input we got from earlier. We’re going to go to the inputs, and we’re going to get the user field. Let’s end our paragraph and end our string. Here’s a little html body with some user input writing here. Now one important thing to know is that it can be dangerous to let users input their own information into an html string, so what I did in the client workflow is I made sure to escape the user input and make it safe. Let’s go back and see that.
The users input, prompt1.result is passed into the encodeHtml function. This function ensures the users input is safe to put in an html string.
Now that I have the body all set up, let’s attach my attachment from earlier. And then, let’s say true to Is Body Html, so the email will actually render it as html and not plain text. Let’s save our server workflow, and let’s go back to the client workflow, and let’s run it in the sandbox!
Let’s send the email to myself (just cause then I can open it and we can see). The email got sent! Let’s go and check my inbox and see what’s there. There it is, 2:37pm! Here’s the html heading that got rendered. My name got injected right in here, and the data got attached and we see CC’d ‘email@example.com’, ‘anotherDeveloper@latitudegeo.com’, and it’s to me and it is from me. Let’s open up the data and just show that it got transferred correctly. Yup, that looks all good.
So that is how you send an email using Geocortex workflow 5 and the on-premise server addition of Geocortex Workflow.”
Geocortex Workflow can extend your Web AppBuilder applications by turning even the most sophisticated business processes into a set of simple, guided end-user interactions. Check out our Discovery Center and explore everything Geocortex Workflow 5 has to offer!