Form is Initializing or Initialized??

Since K2 smartforms 1.0.6, there is a new event, When the Form is Initialized, which runs after When the Form is Initializing completes. The new event allows the Designer to configure rules that runs after a form has been loaded (as ajax calls). This is an important feature as we can now load the form first (forms becomes interactive), then make X number of ajax calls to load the other controls/Views data (e.g. dropdown, List View, etc), instead of loading everything when the form loads. So what does this mean? Let me show you a simple example.

Firstly, let’s create a SmartObject that simulate a large result set or simply a very slow data source (imagining my Oracle and SAP in dev env…). I’ll be using a stored procedure that simulates a 5 seconds wait before returning my result set.

As the procedure name says, it is a very slow script and the corresponding spVSlowScript SmartObject is generated.

222 - SmO
The very slow data source

Next, I generate a View from spVSlowScript SmartObject and made sure to remove all Rules in the View. I don’t need the When the View is Initializing rule.

222 - View
The generated View.

With the View ready, I created a new Form and added 2 instances of the View into it.

222 - Form
The Form with 2 instance of the View.

Now, move on to the Form Rules configuration. You should see the When the Form is Initializing rule added for you.  Let’s edit this rule and change the views method to List. Change the execution block type to also for efficiency (You should use and block if one action returns much faster than the other).

222 - Form Rule
The Form Initializing rule

With the Rule above, the Form will finish loading when both the actions have been completed. Save the Form now.

Testing the Form Initializing rule

In this test, all loading actions (especially the slow view methods) are executed in the initialising rule.

Run the Form URL now and you will notice that the spinner overlay will cover the entire form and the form will only be usable/interactive after the 2 List methods completed the ajax call, which is after 5 seconds. The main interest point here is that your Form takes more than 5 seconds to load, which will fail most of your performance requirements. =(

222 - Initialising Spinner
Whole form spinner overlay.

Testing the Form Initialized rule

Now, let’s try changing the When the Form is Initialising rule to When the Form is Initialized and see the difference.

222 - Form Initialized Rule
Changed the rule to Form is Initialised.

When you run the form again, you will realise that the form actually loads almost immediately (<1 second) and each View will have a spinner overlay to indicate that it is performing an operation now (ajax call). While the spinner overlays are running, the User can start to interact with any controls that have completed loading (e.g. text boxes, etc). Now, you have passed your performance test. =)

222 - Initialized Spinner
Each View running its ajax call now.

Form is Initializing or Initialized?

So in short, you should place the actions that are required on form load in When the Form is Initializing rule and any other actions that could slow down a form loading or could be loaded at a later stage to the When the Form is Initialized rule.

The following is a list of actions that you can consider for the 2 events.

Some example of actions that could be added to the When the Form is Initializing rule

  • OpenWorklistItem action.
  • SmartObject or View methods that loads the main form content. (e.g. The Leave object in your Leave Application)
  • SmartObject or View methods that returns small number of records and the performance is good.
  • Hide/show controls and views. If you already know what to hide or show at this stage, you should do it here.

Some example of actions that could be added to the When the Form is Initialized rule

  • SmartObject or View methods that does not load the main form content and is slow in performance (e.g. large result set that takes a considerable time to load).
  • Hide/show controls and views. If the consideration logics are finalised after all actions in the initialising and initialised rule are completed. These will be added to the end of the initialised rule.

Have fun!

Global Variable in Objective C

Using Global Variable in Objective C, allow you to store static information or values similar to Microsoft.NET C#.

In this post, we are going to using the Singleton design pattern.

Step 1: Create the class in Xcode, add both the header and method file (.h / .m), call it GlobalVariables.

Step 2: Add the following content into your header file.

Step 3: Add the following content into your method file.

 

At this stage, you will be wondering what does all these do. You will be adding @property for those value that you want to be able to access globally in the header file and synthesize them in the method file.

How do we use them?

To access the singleton, you need to import the header file.

First, saving data to the singleton.

Getting Data from the Singleton

Reachability: Testing Internet Connectivity on IOS APP

Introduction

Any apps that you build today will require some form of internet connectivity.

In today’s mobile applications environment, apps are getting more and more intuitive. Users are constantly looking at the apps to notify them of the lack of connectivity.

Step 1 : Getting Reachability library into your Xcode Project

We will be using the following library, Reachability. https://github.com/tonymillion/Reachability

There are 2 ways to setup the app in your Xcode project.

1. Manual
– Check out a copy from the above github url, add the Reachability.h/.m file to your project

2. Cocoapod
– Add the following line to your pod file, pod ‘Reachability’
– Run pod install on terminal.

Step 2: Setting up the SystemConfiguration Framework.
– Go to the Project -> Targets -> Build Phases tab.
– Add SystemConfiguration.Framework into your project.

Step 3: Codes to set up Reachability to test internet connectivity.

AppDelegate.h

Import the Reachability.h, at the very top of the file.

#import “Reachability.h"

AppDelegate.m

Add the codes below to your application did Finish Launching method.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Add the following codes,

Reachability *reachability = [ReachabilityreachabilityWithHostname:@"http://localhost:3000/"];

reachability.reachableBlock = ^(Reachability *reachability) {
NSLog(@”Network is reachable.”);
};

reachability.unreachableBlock = ^(Reachability *reachability) {
NSLog(@”Network is unreachable.”);
};

// Start Monitoring
[reachability startNotifier];

Using K2 WorklistCriteria

In my previous post, I’ve discussed on how to use K2 blackpearl’s SourceCode.Worklist.Client API for basic functions like start Process Instance, open Worklist, open Worklist Item and action a Worklist Item. All these functions are straight forward (that’s about all you can do with it) except the open Worklist  function.

Normally, when you use the OpenWorklist method, you will like to have some form of filtering. It could be a filter to show the user his/her tasks based on the current department website listed or some custom prioritization logic to help the user to focus on the tasks at hand. To make this filtering possible, you will need to make use of the WorklistCriteria class.

Using K2 WorklistCriteria

To use the WorklistCriteria class, you will need to carry out the same open/close workflow connection steps in my previous post, which I’m not going to repeat here. Once that’s done, you will need to create an instance of the class.

You will need to add your filters here, which we will discuss in the next section and lastly pass the object into the OpenWorklist method.

So in the full picture, your codes will look like this:

So if you execute the codes now, it will return all Worklist Items of the current user.

202-Result_without_filter
My result without filter

Filter Basics

Now, to add a filter, you will need to call on the AddFilterField which has 3 variations:

WCField is the list of properties you can filter on and they are pretty much self explanatory.

Do take note that WorklistItemStatus comparision uses the following values:

WCCompare lists the comparison operators you can use in the filter:

If you notice, there is no “greater than”, “greater than or equal”, “less than” and “less than or equal” operators here, so you will need to put some thoughts into your mathematical operations (=

WCLogical is the joining operator between 2 filters. This will be discussed in more details in a subsequent section.

SubField is a string value used to reference additional key names like Data Field name during comparison.

Object is a object value for your comparison.

So if you just want to filter and show all Worklist Item with “Available” status, the code will look like this:

When using my test Worklist, I’ll get:

202-Result_only_avail
Result showing all “Available” status only

Using AND and OR Logical Operators

Using the AND and OR filter is pretty straight forward.

In my AND join example, I’m going to create a filter that requires the Process Name to start with “C” and the Worklist Item status to be “Open”.

202-ProcessCAndOpen
Result for Process start with “C” and status = “Open”

In my OR join example, I’m going to create a filter that requires the Worklist Item status to be “Available” or “Open”.

202-StatusAvailOrOpen
Status = “Available” OR “Open”

Using the Other Operators

Other than AND and OR operators, the following shows what the other operators does:

StartBracket: Draws the “(” operator for the given filter.

AndBracket: Adds the AND operator and closes the filter with a “)” operator.

OrBracket: Adds the OR operator and closes the filter with a “)” operator.

EndBracket: Closes the filter with a “)” operator, if you have a StartBracket earlier on

Filtering by Process or Activity Data/Xml Field

If you need to filter by Process or Activity Data or Xml Field, you will need to pass in the field name in the SubField like the following:

 

Well, the above details should get you through majority of your needs to create a custom Worklist. Enjoy!!