Serial If/Then conditions in SharePoint set up automation waterfalls that are efficient. This example shows how to apply If/Then to transaction flow.
In the new position request workflow, we use something called a Serial If/Then set of conditions. We said, IF the Area VP approves THEN. We check to see IF the Finance VP approves and THEN. If the HR VP approves then and only THEN is the position approved. So we're actually going through each of these steps, we're checking to see if the area VP approves and if they do we don't get to say well that's good enough, we can now process the new employee indeed. All that does is give us permission to ask more peoples' opinions about whether or not we should be having this new position.
So serial If/Then. We do each of them and we do them in order. There are a couple of other options about how we might want to arrange conditions. The next one that we're going to look at in this particular movie is not serial If/Then, it's actually called, If -Then - Else. So let me introduce you to another list. It's the credit card transactions list. I craeted this list very quickly and easily. It has, simply, a title, a drop down list with the three types of credit cards that we take which are Visa, American Express, and Mastercard.
The ability to enter an amount, with two digits so it looks a little like currency, and the ability to store some text, the credit card number. You would never create a workflow or a list like this that crack credit card numbers, just don't do it because there are laws about how you have to secure things like this so, I don't want you to walk away and say oh, I'm going to create one of those, don't. If you want to do something like this, just buy a square. But, this is a good example because we all understand broadly what credit cards do and that there are types of them.
So if we were to adapt exactly that same serial, If/Then, process, let's see what that would look like. Here it is in our new position request, and if we used it for a credit cards what we do is we say well, we're processing a credit card. If the type is American Express, then let's use the American Express gateway. Or the American Express formal process. And then we check and say well is it a MasterCard? If it is, then let's use the MasterCard gateway. And if it's a Visa, then let's use the Visa gateway. The problem here is, that we only need to do this until we get a yes.
If the credit card is an American Express card, we never need to ask if it's a MasterCard or Visa. We're done. And so this is different than, that the serial, If/Then conditions in fact what we want to do, is we want to check first and see if it's an American Express card. If it is, then we simply are going to process the card using the Amex gateway, and we're done. What does this look like? Well, we have else is in here, and there's our clue. So, if the type is American Express, then use the Amex Gateway. Else or in other words otherwise and only otherwise, see if it's a MasterCard.
What if it's not a MasterCard? Well, then and only then, else see if it's a Visa or possibly sometimes when this is created, there won't even be a check to see if it's a Visa. If it's not an American Express and it's not a MasterCard and we know it's a credit card, it must be then that we're going to process this using the Visa gateway. Because we only take American express, Master Card and Visa. So this is what the If - Then - Else condition looks like. Its a different kind of a condition and we're going to create this differently when we create the workflow.
Let's swing over to our list and create a workflow for it, so you can see what the tools here are. Here we are in our list. We could do this in SharePoint Designer, but I'm simply going to go to my list, go to Workflow Settings, and Create a new workflow in SharePoint Designer. Of course, I have these three dialogs where I need to allow them, but other than that, it's not a bad thing. And we're going to call this process cc transaction. And this is a demo. I'm going to say OK. So in the first stage, what we're going to do, we're actually going to do two whole things.
We're going to determine card type and process transaction. It's a pretty good description of what's going on here. So we'll start, then, with a condition. If any value equals value, just as we did in our last example. So if, in the Current Item, the credit card type, equals American Express. Cool, then we would do something, we would process this and we, we might have some code to do that or whatever else we might want to choose. I'm simply going to insert a comment here.
Add a comment. I'm simply going to add a comment that says, process using Amex Gateway. Just so we have something here. And this doesn't do anything. All it does is it serves as a placeholder, and reminds me we need to do something else. Now, what we want is an Else branch. And this is the part that's not only important, but it's different. This is not how we did this in 2010. So, while I'm on the If. Here's my If and the action that I am taking, and I want to click right here and I'm going to add an Else.
So, remember Else, I still need to ask If. Because all I know is it's not an American Express. So, if, in our current item, the credit card type equals MasterCard, then I'll just go ahead and insert my comment again, add a comment, my comment text is, process using MC gateway. Okay, one more choice, one more Else. So I want to be here, say right here, around the place of our comment, a little before our comment, and I'm going to insert another Else.
And I can do the If, if I want again. So I'm going to say If, in our current item. Our credit card type is equal to Visa, I like pulling those off a drop down list, then we'll just add a comment, and that will be process Visa gateway. So this is our If, Then, Else. Let's walk it. If the credit card type equals an American Express, then process it using the American Express Gateway. And we're done.
Else or otherwise, another way to think of the word Else. Check to see. Is it a MasterCard? If it is, process it using the MC gateway and we're out of here. But, if it's not, Else, if it's a Visa use the Visa gateway. So this is how we construct If, Then, Else. We could have all of these done serially. We would just be checking every single transaction three times whether it needs it or not. And clearly only the Visa transactions would need to be checked three times.
One more quick thing, I did these in the order in which they appear on the list. But if 80% of the transactions we process are MasterCard transactions, why not put them first, it's more efficient. We actually would want to structure this, either in some kind of alphabetical order for text, numerical order for numbers and chronological for dates, or you want to put them in the order in which they are most likely to be chosen. I'm liking this and so I'm going to save, well, I need to do one more thing.
I need to say how we're going to end this workflow. So I'm going to go to stage, and the stage is going to be the end of the workflow. This will allow me to check for errors. I don't have any, and I'm going to save this, it's going to come back, this workflow, much later in this course when we talk about some other best practice topics around workflow design.
- Automating workflows
- Documenting workflows with Sticky Notes, Excel, and Visio
- Driving workflow interactions with forms
- Using workflow actions
- Making choices and controlling flow with conditions
- Creating a simple form
- Using email notifications
- Pausing and stopping workflows with core actions
- Building a dictionary
- Creating a site workflow
- Deploying workflows
- Creating workflows visually