This guide goes through some best practices for developing K2 applications.

Forms

Below is a list of additional things that are needed for every K2 SmartForm.

Form name

The form name should be made up of the following: [ProjectName].[Area].smf.[Name of form]. So for example a form name would look like DMO.TST.SMF.DemoForm.

Form description

The form description needs to be filled in with a basic description of what it does, plus its story number and form number. The form number should be in this format: <form number>, for example <FM0001>. This makes it easy for people to identify what the form does and what it relates to.

For rule actions, it’s recommended to run them concurrently if you do not need to pass data between the actions or rely on the result of the previous action.

Views

Below is a list of additional items needed for a view.

View name

The name of the view is made up the same way as a SmartForm. The only difference is that instead of ‘.smf’ it’s one of the following: [ProjectName].[Area].vwi.[Name of view] for an item view, or .vwl for a list view.

View description

The view description needs to be filled in with a basic description of what it does and its story number. This makes it easy for people to identify what the view does and what it relates to.

View properties

View input controls and labels are in the same column.

View controls

The controls on the view also have naming conventions. Each one has a prefix, and some have a guide width.

Display controls:

  • Content: ctt (cttMyControl)
  • Label: lbl, 200px (lblMyControl)
  • Picture: pic (picMyControl)

Input controls:

  • AutoComplete: auo, 200px
  • Calendar: cal, 100px
  • Check Box: chk, 150px
  • Check Box List: chl, 150px
  • Choice: che, 200px
  • Data Label: dbl, 200px
  • Drop-Down List: ddl, 200px
  • Hyperlink: hyp, 200px
  • List Display: lst, 200px
  • Lookup: lku, 200px
  • Multi-Select: msl, 300px
  • Picker: pkr, 200px
  • Radio Button: rdo, 150px
  • Radio Button Group: rdg, 150px
  • Radio Button List: rdl, 150px
  • Rating: rtg, 150px
  • Rich Text: rxt, 400px
  • Slider: sld, 150px
  • Text Area: tar, 400px
  • Text Box: txt, 200px
  • Tree: tre

Action controls: Button (btn), Timer (tmr), Toolbar Button (tbr). Attachment controls: File Attachment (fat), Image Attachment (iat). Layout controls: Table (tbl).

The size is only a guide, and common sense must still be used for every control apart from the label.

Control watermarks

Each control should have its own watermark, relating to the label the control belongs to and not just the default ‘Type a value’. The watermark must be all in lower case. The image below should help demonstrate this.

When to use a drop-down list or a picker control

Using drop-down lists to select reference data is in most cases an acceptable approach, as everybody knows how to use a drop-down list. But it does have a couple of drawbacks:

  • It can take the form a long time to load if there is a huge amount of data to populate the list
  • When the user interacts with a drop-down list holding a huge amount of data, it becomes a nightmare to use

We do have an answer to this, and that is to use the picker control instead. It gives speedier loading times and lets the user search for specific data more easily.

The rule is: if the reference data is longer than 20 rows, use a picker control. You set up the control in exactly the same way as a drop-down list. The only difference is that you can choose which properties can be searched against.

Setting up a picker control

  • Drag a picker control onto the view, or change an existing control into a picker control
  • Give the control a name using the correct naming conventions
  • Select SmartObject under data and set it up as you would a drop-down list
  • Select which properties you want to filter against
  • Click OK
  • In the picker control properties, untick ‘Allow Multiple’

Required fields

If a control is required, we can show this graphically by adding a *. To do this:

  • Select the label of the field or control you want to modify
  • In the properties tab, find the Text property
  • At the end of the text, add the following HTML: <b style=’color:red’>&nbsp;*</b>
  • Make sure the Literal property is enabled
  • In the Tooltip, put the text of the label without the HTML

Control data cache

Please make sure data caching is not enabled on your data list controls, like drop-down lists.

Label to control spacing

As mentioned in the list of view controls, labels must be set to 200px with the Wrap Text property set to True.

Read-only controls

Read-only data will be shown in data labels with Read Only enabled and a name starting with ‘dblReadOnly’. So if a Lastname needs to be read only, it would be called ‘dblReadOnlyLastname’.

View rules

The pattern we use is smart views and dummy forms, so to get this to work properly we have to use unbound rules.

How to create an unbound rule

An unbound rule is one that is not bound to an event, such as a button being clicked. To create one:

  • Click on Rules, then Add Rule
  • In the right-hand panel, click on ‘Enter Rule Name’
  • Start the rule name with the word ‘Unbound’, followed by what the rule does
  • Add conditions and actions as normal

Reducing the load with editable list views

Because of the number of rules called on an editable list, there is a new approach that dramatically reduces those calls.

  • Create a list view, but don’t enable the editing options
  • On the view layout, drag a couple of toolbar buttons to the top of the view and name them ‘Add’ and ‘Edit’
  • Add a parameter for the primary key of the data the list view is bound to
  • Click Finish
  • Create an item view based on the same SmartObject used for the list view
  • On the item view, add a button called ‘Save’
  • Add a parameter with the same name and type you used in the list view
  • Add any other parameters you need, such as the rest of the best-practice parameters
  • Click Rules, then Add Rule. The event is ‘When a view executes a method’ (initialize), the condition is ‘If the view parameter contains a value’ (the primary key parameter), and the action is ‘Execute a view method’ (Load), with the input parameter ID set to the view’s primary key parameter
  • Click OK
  • Create an unbound rule to check the validation of the view
  • Create an unbound rule to either save or update the data, depending on whether the ID parameter is populated, as in the earlier rule
  • Create a rule for when the Save button is clicked, which checks the view validation rule and then calls the ‘Unbound Save Data’ rule you just created

Now that we have built the rules to save, update and load the information, we can add it to the list view. Open the list view in edit mode and go to the rules.

  • Create an unbound rule called ‘Unbound PopUp View’. Its action is ‘Open Subview’ (select the item view you just created), configured to execute the view’s Load method, mapping the list view’s primary key parameter to the item view’s primary key parameter
  • Create a rule for btnAdd that transfers data into the primary key parameter (tick the check box but leave it empty) and then executes the ‘Unbound PopUp View’ rule
  • Do the same for btnEdit, but without the transfer data action
  • Create a rule so that when you click on a list item, it transfers the primary key from the list into the view parameter
  • Finally, add an action to close the subview once Save has been clicked. Click on the ‘btnSave is clicked’ rule and click Edit
  • Click on the Actions tab, search for ‘Close’ and select the ‘Close Subview’ action
  • Click OK and Finish

You can now test the view to make sure it’s behaving correctly. When you click Add, it should load the item view empty, and clicking Save should insert a new record into the list. If you click on an item in the list and click Edit, it should load the data for you to edit, and clicking Save should update any changes.

Workflow

This section looks at what is needed in every workflow.

Where to create the workflow

The workflow is to be created in Visual Studio, so it can be checked into TFS.

Workflow name

Like the views and SmartForms, the name must show what part of the project it relates to: [ProjectName].[Area].wf.[Name of workflow].

Workflow description

The workflow description should be filled in, so people know what it does and what story it relates to.

Workflow data fields

Data fields should be kept to a minimum and only hold reference data like a primary or foreign key. You can then use the reference option to get the rest of the data you need.

The following check boxes also need to be unticked: Hidden, On Demand and Keep Audit.

Workflow activities

Activity names should say what they do, and the activity description should contain information such as whether there is a start rule or any escalations. To describe which activity rules are used, you can use these abbreviations: PR (preceding rule), SR (start rule), ER (escalation rule) and DR (destination rule).

Activities are colour coded to make it easier to see what they are doing:

  • Start: green
  • Client activity: blue
  • Server activity: grey
  • IPC activity: yellow
  • End activity: red

Activity events

Activity events should say what they are doing and not be left with the default names. If a server event contains code, the event name should be prefixed with ‘CC’.

Please note it is not ideal to put code directly into the workflow, and you must consult your K2 lead before doing so.

Line rules

Line rules must have a label prefixed with LR, followed by what the rule is checking for, as seen in the image above.

Line colours

Outcome lines should also be coloured to show what they are doing and to help visually navigate the workflow. This is especially helpful in larger workflows.

  • Approve (positive line): green
  • Reject (negative line): red
  • Rework line: blue
  • Normal line: default

SmartObjects

This section looks at what is needed in each SmartObject. If you have a number of stored procedures that interact with the same table, the same SmartObject can be used with the additional methods and properties added.

Where to create a SmartObject

SmartObjects should be created in Visual Studio and in the correct folder.

SmartObject name

Like the rest of the K2 artefacts, the SmartObject name should follow the same naming convention: [ProjectName].[Area].smo.[Name of SmartObject].

SmartObject description

The description should say what the SmartObject does and what story it belongs to.

SmartObject parameters

All required input properties should be parameters and be prefixed with ‘p’.

SmartObject properties

Properties must be named correctly, with no ‘PropertyName(1)’. There should be no spaces or underscores in names; use camel case.

Each property should have a description saying what it does.

The correct property data type should be used, and most of the time K2 takes care of this automatically. The only exception is file types: you will need to manually change the file property’s data type from Memo to File.

Methods

When creating a method, check the following:

  • Method name: it should say what the method does
  • Method description: it should describe what the method does and which stored procedure it calls
  • Method type: in some cases the correct method type is not selected after the service object method is chosen

So once the service object method has been selected and the properties created and bound to the service object, you need to edit the method and choose the correct method type.

For example, a stored procedure that returns a single row of data is sometimes set up as a list method. This is incorrect and would cause problems later on in the view design. In this case you would change the method type to Read and then save.

Testing SmartObjects

After creating the SmartObject, you can test it with the SmartObject Service Tester. If it’s not on your task bar, it can be found at C:\Program Files (x86)\K2 blackpearl\Bin\SmartObject Service Tester.exe.

To test your SmartObject:

  • Open the tester tool
  • Expand SmartObject Explorer
  • Navigate to your SmartObject
  • Right-click on it and select ‘Execute SmartObject’
  • Select a method from the drop-down list, fill in the parameters as required and click Execute
  • Any returned data will appear underneath the parameters