The Mid Function

October 4, 2019 Josiah Feuerbacher

This week’s post goes out to some of our more advanced users. We’re going to take a first look at Functions, and how they’re used in FWI.

Anyone with programming experience, or who has even dabbled in learning a programming language, is going to know what a function is. You can Google “Programming Function” and find an overwhelming amount of information on the topic. To sum it up, a function is like a mini program. It’s going to take information (called parameters) and return to you some calculation off that information.

Think of it like a calculator. A calculator might have a bunch of functions (add, subtract, multiply, etc). You give the calculator information, like add 1 plus 1, and the calculator gives you back (or returns) the number 2.

Ok, so enough of the basics, let’s take a look at a function in Content Manager. Today, we’re going to look at the Mid function. Mid allows you to pull out a selection of characters from a word or sentence by specifying a couple of parameters. It’s a pretty common function, and you can see all the technical details here

For now, let’s just look at some example syntax and breakdown exactly what the Mid function is doing:

mid(‘Hello FWI!’, 0, 5)

In the example above, I’ve formatted each of the parameters, which are separated by commas. The first parameter (in italics) is the string of characters that we want as our input. The second parameter (in bold) is the starting point of our search, and the third parameter (unformatted) is the number of characters we want to search for. So given the example above, the end result would be:

‘Hello’

Starting at position 0 (before the ‘H’), we move 5 characters to the right. The single quotes are required in the function when you manually type in the string, and they don’t count toward your characters count.

Below are a few more examples, and what they would output.

mid(‘Hello FWI!’, 0, 3) = ‘Hel’

mid(‘Hello FWI!’, 3, 5) = ‘lo FW’

mid(‘Hello FWI!’, 0, –4) = ‘FWI!’

Notice in that last example that you can work backwards, or from the end of your input string, by specifying a negative number.

Also, if you want to bring in a variable or a field from live data, you can place the field name or variable in square brackets, like this:

mid([your_field_name],0,3)

So that’s a lot of background. But how do we use this in FWI? We can use these functions in a lot of places. We can use them in live data markup fields, in filters, or anywhere we need to chop up some text. When we use functions in FWI, we always have to use them in an expression. If you don’t know what an expression is, don’t worry, we’ll cover that in another post soon…

Let’s look at a couple of real examples using Live Data. Let’s say you have a data source with a field called “Phone_Number”. Inside that field, you have a phone number in the format of ‘123-456-7890’. You may want to display only the last 4 digits of that number in a live data row. In this case, you could drag down a markup text item, and place the following text:

{&exp:mid([Phone_Number],0,-4)}

This will display only the last four digits of that number in the marktup field. Notice that the mid() function is wrapped in an expression, and we use square brackets to point to our Phone_Number field.

Next, let’s say you want to filter the data, and only show phone numbers that have the area code ‘555’ (such as 555-123-4567 or 555-221-1234). In this case, we’ll select the “Filter” tab at the top right corner of the live data window, and drag over a marktup text item. A textbox will pop up, and you can add this expression:

{&exp:mid([Phone_Number],0,3)}

You can leave the operator as ‘is’, and click the ‘Value’ field and enter ‘555’. So the entire filter looks like this:

{&exp:mid([Phone_Number],0,3)} is ‘555’

Now you will only be displaying those items with area code ‘555’.

The mid() function can come in pretty handy when you need to filter or hide particular sections of data. But it is just one of many functions that are available inside the FWI Platform. Stay tuned and we’ll look at some of those other functions in future posts!

Previous
How MGM Resorts Capitalizes on Visual Communications
How MGM Resorts Capitalizes on Visual Communications

RANDY DEARBORN, A VP AT MGM RESORTS INTERNATIONAL, EXPLAINS HOW USING VISUAL COMMUNICATIONS HAS CONTRIBUTED...

Next Up
Copying Content, Players, Templates or Locations
Copying Content, Players, Templates or Locations

The very first installment of DoYouFWI