Find Next Month using Expressions in K2 Designer

 

I need to find the number and name of the month after the current month using a SmartForm. We’ll do it using a pair of expressions.

Here’s the walkthrough.

Warm up Designer. Open up the layout of the view or form that requires the data. Click on any text box in the layout. (If you don’t have any, create one and make it invisible.) It’d be to your advantage to use the one that will display the product of your expressions.

In the lower right corner of the browser, you’ll find the control’s properties. Properties are divided into three sections: Detail, General and Validation. In the General section, look for a control labeled “Expression.” The control looks like a textbox, but has a button at the end marked with a set of ellipses (“…”). Click that button to launch the Expression panel.

gfonmd-3

The panel appears with a toolbar at the top and a pair of buttons at bottom right. Click the Add button in the toolbar to create the first expression.

This launches the Edit Expression dialog. There’s a header across the top with a Name field, a large field below called Expression Details, a Preview region at the bottom, and then a Context Browser at right.

Get First of Next Month Datetime

The first expression you’ll create we’ll call “Get First of Next Month Datetime,” because I honestly can’t think of a shorter name to describe what it does.

After entering that (or a better) name in the Expression Header, focus on the Context Browser.

The Context Browser features a tabbed interface — by default, the active tab is called Context; the tab behind it is labeled “Operators.”  Click the Operators tab.

If you’re familiar with K2 Studio, this tab will seem familiar: it contains several categories of operators that can be plugged into your expression.

gfonmd-2

Let’s expand the Date and Time node.

Drag the following operators into the large Expression Details field, so that your expression resembles the following:

gfonmd-1

That value is

Add Days (End of Month(Today))),1)

 

Validate the construction by clicking the toolbar button, then click OK to close the Edit Expression dialog.

One down, one to go.

 

Get Next Month Name

We’re going to create a second expression. This one will grab the name of the month out of Get First of Next Month Datetime:

gfonmd-4

That code is:

Format Date and Time (Get First of Next Month Datetime, MMMM)

 

As you can see, we needed the first expression to get what we really wanted using the second expression. As before, validate the expression and close the Edit Expression dialog.

If this is the textbox you want to use your new expression, make sure it is selected and click OK to close the Select Expression dialog. Otherwise, select “None” from your list and close the dialog. Your new expressions will remain available for use within that view or form for other controls to use.

Find the textbox you want to consume your new expression, and select it from the General Properties of the control like you did before.

You’re not limited to consumption of expressions in the Layout view; you can use them in Rules, too — which means you can add expressions to notifications, e-mail messages and so on.