[.Net Post] – How to obtain code coverage of .Net code using OpenCover (an open source tool) and generate report using ReportGenerator tool.

Click Here to See Post

Using States in Smartforms to manage approval Views at different stages of workflow

Let’s see how we can use Smartform’s states to show different views at different approval stages of a workflow using a sample process as shown below

Process Flowchart


Now above flowchart has 3 approval activities Manager Review, Final Review & User Acceptance. In general approach, we need 3 forms for above activities and 1 for submitting the request so total 4 forms. Now using these states, we just need one form to handle all these. Let’s see how we can do.

Step 1: Creating Views and Forms

We need one view to submit the request & one for approval activities. Design 2 views as below

View 1: SubmitView


View 2: ApprovalView


Now create one smartform and add these views in that. Note that ApprovalView needs to be dragged twice which we are going to use one for ManagerApproval & one for FinalApproval. Please see below screenshot.

Here in form I have took 3 tables which has 3 buttons in each of them. These tables will be shown according to approval activity.


Step 2: Creating a Smartobject

Create a smartobject to store the data of the all form fields. Here I have created a smartbox smartobject as below


Step 3: Create Workflow

In designer, create a new workflow give it a name, in forms section select the form that we have created above, and select Use an existing state and select Base State


Create a data field RequestID


Now in configure start rule of workflow, form rules will be automatically populated. if it doesn’t show up here, we need to write the submit rule in form and come back here to configure this step.

Here I have already written those rules in submit button click rule of form.

Now finish.


Creating Manager Approval Task

  • Now drag a new User Task on to canvas.
  • Give Manager Approval as name.
  • Add Approve & Reject as actions & Check 2 checkboxes that are shown there and Click
  • It will show outcome settings just leave the options as it is and click Next.
  • In Participants section drag the Manager to the task group.
  • In UserForm Section select Create a new State option give ManagerApproval as name & click Action Settings button select I will configure the action later option and click Finish and click
  • In next form let the default options as it is and click Finish.

Check the screen shot below


Now similarly configure the other 2 approval activities Final Approval & User Acceptance. Both activities should have the same form that we selected above and in every case we need select create a new state option and give FinalApproval & UserAcceptance as state names

And in all reject cases send a mail using email event and also in accept case too.

Below is the workflow screen shot after changes.


Step 4: Configure Smartform rules

Now when you open the smartform and navigate to rules section you should see 4 states, (Base State), ManagerApproval, FinalApproval, UserAcceptance. See screenshot below


State are similar to views in SQL, they are used to show the data according to the user or approval activity.

Here in this case (Base State) is considered as a form to Submit Request.  In this state, we will hide the other 2 views and show buttons that are used to submit the request . Rest all controls are made hidden. This will be considered as the default state of this form. It will look as below screen once the rules are configured


Please note that all the base state rules will be automatically derived into other states.

  • Now let’s configure the next State ManagerApproval.

Click on state ManagerApproval and see the rules that are in base state are already appearing here. Here I’ve created an unbound rule LoadManagerApproval in which I have wrote the rules for hiding the controls of submit state, make the second view visible and make the controls in first view as non-editable.


Now in form initializing rule you should see a rule which got automatically added from workflow.

Here in open Manager Approval Worklist item rule configure options get the RequestID from output mappings of the workflow Datafields. Use this RequestID to load the data from smartobject and populate in first view.


Same way we need to configure the other states by showing and hiding controls/views based on the approval activities. Once all the rules are configured the forms should look as below

SubmitRequestView (BaseState)

Once the request is submitted. 14.submitState

Manager Approval (ManagerApproval State)

Once the request is submitted approval task will be assigned to his manager and below is the screen shot of the how this view would look like. Now Manager reviews and provides his feedback and approves the request.

15.ManagerApprovalState.jpgFinal Approval (FinalApproval State)

Below is the screenshot of how the approval form will look like. Final Approver will review the ratings and provide his feedback and sets the final rating and approves the request.



Now the requestor gets the task to review his rating and accept it.

User Acceptance (UserAcceptance State)

User gets the task to review his rating and he can either accept or adjust/Resign 😊


Once he accepts, the workflow will end and task will be completed.

That’s it!! This is how we can use smart form states to show a single form to show different views at different approval activity levels.

Combining ASP.Net form with K2 Smartform using IFrame

This POC is about how we can integrate K2 smartform into an ASP.Net form which is using Iframe and pass data from ASP controls to the K2 smartform controls.

Let’s see how we can do it.

First create a simple K2 Smartform (POC.SMF.ASPSmartForm) with 2 parameters Value1 & Value2 and 2 Textbox Controls. In form initialize rule add transfer data rule to transfer parameter values to textbox values.


Next create an ASP.Net form with name ASPSmartForm.aspx in which we have to take 2 textboxes Textbox1, TextBox2 and an Iframe control (Name: myK2IFrame) for which the URL we have to set the URL of smartform which we created above.

i.e. http://k2-runtime/Runtime/Runtime/Form/POC.SMF.ASPSmartForm/



Now in aspx page head section add below Javascript  code (Method Name : SendData) which gets the data from textboxes and passes to k2 smartform

<head runat="server">
        function SendData() {
            var tb1 = document.getElementById("TextBox1");
            var tb2 = document.getElementById("TextBox2");
            var myK2IFrame = document.getElementsByName('myK2IFrame')[0];
            if (tb1 != null && tb2 != null)
                var URL = "http://K2-Runtime2/Runtime/Runtime/Form/POC.SMF.ASPSmartForm/?Value1=" + tb1.value + "&Value2=" + tb2.value;
            if (myK2IFrame != null)
                myK2IFrame.src = URL;


Now in textbox controls add onChange Event and call the SendData JavaScript method

<asp:TextBox ID="TextBox1" runat="server" onchange="SendData()"></asp:TextBox>        
<asp:TextBox ID="TextBox2" runat="server" onchange="SendData()"></asp:TextBox>


Now if we observe the code whenever value is changed in any of the ASP text boxes then the same value will get populated in the K2 Smartform TextBoxes. We are using URL Parameters of K2Smartform to pass the values from ASP to K2 Smartform.  Now save the aspx and the final form should look like below.


Run the form in browser and enter the values in asp textbox controls  to see the values getting passed in to K2 textboxes. see the gif below.


That’s it, this is how we can integrate ASP.Net forms with K2 Smartforms and can extend their possibilities and features to a wider prospects.

We can extend this POC to get the data in reverse from K2 controls to ASP Controls.

Thanks for watching!!

Using FilterXML parameter in SmartObject REST Services

When you are using K2 SmartObject REST services then you would have observed a query parameter with name FilterXML for all the list methods. This parameter can be used to filter out the data while executing the list method of SmartObject. But using this parameter is a kind of tricky for beginners unless you follow this simple trick which I’m going to explain below.

Let’s see a sample SmartObject (Students.SMO) which returns list of students as below.


Now the SmartObject Service’s REST endpoint URL for above SMO will be as below

https://k2-server:8443/SmartObjectServices/rest/Vijay/SmartObjects/Students.SMO/Get List?$format={format}&$top={top}&$skip={skip}&filterXml={filterXml}&RollNumber={RollNumber}

As RollNumber is the id column of Students.SMO  smartobject, By default REST URL is giving us the RollNumber as a URIParameter

Now if you want to use other columns as a filter to get data, we have no other option than using filterXML.

As the parameter says it accepts XML based filters.

Now let’s suppose there is scenario where you want get the list of students where percentage is greater than 90. Now the filterXML for this would be like below

Condition: Percentage > 90

     <propertyexp name="Percentage" sotype="Text" />
     <valueexp sotype="text">90</valueexp>


Condition: Percentage >= 90

         <propertyexp name="Percentage" sotype="Text" />
         <valueexp sotype="text">90</valueexp>
        <propertyexp name="Percentage" sotype="Text" />
        <valueexp sotype="text">90</valueexp>

 Now we just have to pass this as a value to URIParameter filterXML

https://k2-server:8443/SmartObjectServices/rest/Vijay/SmartObjects/Students.SMO/Get List?$format=JSON&filterXml=<filterexp><greaterthan><left><propertyexp name=”Percentage” sotype=”Text” /></left><right><valueexp sotype=”text”>90</valueexp></right></greaterthan></filterexp>

Now the simpler way to create these filterXML values is using SmartObjects – Services-Tester utility tool. Select Execute Smartobject and click Set button beside filter option which is shown highlighted in below screen shot


Now in below screen we need to select the column that we want to use as filter in Left Property (here it is Percentage) and in Logical Filter select the logical operator (here it is GreaterThan) and Right Property you will have an option to select a column or directly provide a value (here in my case it is 90) and click add to see the xml representation of filter. See below screen shot


Now copy the xml from the bottom window, remove the first line (<?xml version=”1.0″ encoding=”utf-16″?>) and then you need to add <filterexp> and </filterexp> at the beginning and end of the copied xml respectively. Also remove the line breaks and spaces in the copied filterXML and then it ready for use.

Copy paste the url in chrome and hit enter button to see the data getting filtered as mentioned in filterXML


Creating Endpoint REST Service instance for a REST api which needs authorization bearer token


This post is in continuation to my previous post K2 Integration with REST Api Services which explains how to integrate K2 with REST Api Services. In my previous post, I have integrated with an Api Service which doesn’t require any Authorization Token that needs to be passed. But there is a chance that you find some REST api Services that needs an authorization bearer token to be passed to execute its methods. Now in this post we will see how to integrate to one of those REST Api services which needs the Authorization Bearer Tokens.

To get the swagger file follow the steps that were mentioned in my previous post which is using RESTUnited.com. There will not be any changes in steps to generate swagger except in authentication tab you will have to mention authentication token details and add it which will be as shown in below screenshots.





Now once we get the Swagger file generated proceed to create Service Instance using EndPoints REST option in Smart Objects – Services – Tester Utility.

Now in Service Keys Section, Default HTTP Request Headers field you need to add this Authorization Token key in below format without any line breaks

{“$type”:”SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader[], SourceCode.SmartObjects.Services.Endpoints.Common, Version=, Culture=neutral, PublicKeyToken=null”,”$values”:[{“$type”:”SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=, Culture=neutral, PublicKeyToken=null”,”Name”:”Authorization”,”Value”:”Bearer eyJhbGciOiJub25lIn0.eyJVc2V==”}]}

*Replace the Values with the token that needs to be passed. Also we can pass multiple header Tokens here.

Now give the path of the Swagger file in the descriptor location field and leave rest of the options with default values


That’s It, Now just create a SmartObject using this Service instance and execute to see the result.

If you get any error with message like “Unable to Deserialize…” then its issue with the format of token that’s passed in HTTP Request Headers section…Just ensure that it is in above mentioned format without any line breaks . That’s It.

Also please note that this procedure should be used only for development purpose as per K2. Don’t ask me the reason (B’cuz I too don’t know :))

Note: Recently, when one of my friend tried to create a SmartObject over a REST Service instance that he created for a REST service which needs authorization bearer token, he was constantly getting 401, 404, 0 as response code but the same service he was able to run from Postman and fiddler without any issue. He tried all above mentioned things but still we couldn’t figure out what is the issue with REST when we are trying to connect with K2. so we approached K2 Team for help and when they investigated they found that its the issue with REST Service Api URL which has spaces in it and K2RESTBroker is trying to encode the URL which is already encoded…so as a fix we have removed spaces in REST service endpoint URL and the k2 is still investigating the actually issue behind the k2 encoding the already encoded URL. So just ensure that your REST Service URL doesn’t have any spaces in it.

Below are the community posts which will give you related information regarding this.


Using HighCharts in K2 Smartforms



High Charts are the customizable Out of the Box charts that we can integrate with Smartforms and are useful to improve the Visual Experience of data. These are available in K2 Market and doesn’t need any license to use. Below is the link from where we can download these controls


A zip file gets downloaded which needs to be extracted. Once you extract the file you will get 2 folders, an installer folder (V2.1 K2Field.K2Forms.Controls.Charting Installer) and the other one is the VisualStudio Solution folder(K2Field.K2Forms.Controls.Charting) with all the project files. Along with folders you will get some images and a document explaining about the usage of various HighCharts and its available customizations.

Now copy the folder V2.1 K2Field.K2Forms.Controls.Charting Installer to the K2 Server and run the RegisterCustomControl.bat bat file as administrator which will register the controls in K2 Smartforms. Once the bat file running completes restart K2 Blackpearl Service Instance. Now open Smart forms desinger and see the controls section and scroll down to see these Custom Controls available for use in SmartForms.



Now let’s see how we can use these charts to show the data.

I have a Student’s SMO which gives list of student details. Now I will use these details to create a BarChart.

Create a new view and drag and drop Bar/Column/Line Chart control to the canvas. In Properties Section give chart Control a name and select the chart type that you wish to create. Now scroll down to DataSource Section and click the elliptical button to write an ADO Query using the Smartobject which gives the data.


Write the Query similar to SQL Query but instead of table name use the smartobject name that gives you the data.

** You may not have all the Query options similar to SQL but most of them will work.

Here in my case SMO name is Students_SMO and the columns that I need to use are Name & Percentage so my query will be “SELECT Name, Percentage FROM Students_SMO”.

Once you write the query just click test Query to see the Chart preview on left and if everything looks good then click ok.


Now go to the Rules section and from Events tab select When the view Executes a method and select initialize and then from actions tab select transfer data rule and transfer text GO to bar chart control.


Now we are done Just save the view add it in a form and run the form to see the result.


That’s it this is how we can install and use the Custom Chart controls.

Thanks for Watching!!


Configuration setting to deal with Optional Parameters while creating SQL Service Instance

Have you ever faced this situation while creating a SmartObject method for a SQL stored procedure, if the SQL stored procedure has some optional parameters like below, but in SmartObject it still shown as a required parameters?

Sample stored procedure with optional parameters (parameters with default values)

    @Parameter1 VARCHAR (100) = 'User'
  SELECT 'HELLO ' + @Parameter1 AS [Message]


Here @parameter1 is an optional parameter which is when passed then Stored Procedure will return ‘Hello Parameter value’ if not passed then ‘Hello User’

SQL Execution

Now without changing the configuration setting if we create SmartObject then it will throw error as below  when we are not passing the parameter value.


Now when we pass parameter value then it will give the result


Now to make this parameter as optional we need to modify the service instance and set this attribute Use parameters for stored procedures to False (by Default it is True) and save.

Service Instance Setting

Now recreate the SmartObject and execute the method without passing the Parameter Value which will give you the result.


A simple yet very useful setting right 🙂 !!!!