What are K2 Composite Smart Objects and how to create them.

Capture
K2 have provided a great feature to join data from multiple data sources into single dataset. If your application has data coming from multiple lob’s like SQL, Sharepoint, WCF Services, REST Services etc and you need to combine the data and show them as single dataset then composite smart objects are perfect pick for you. They are like Joins in SQL, but the data sources can be different.
Let’s see how we can create with an example.
**Before moving further, I would like to mention you that Composite SmartObjects can be created either in VisualStudio or K2 Studio. (In K2 Designer we can’t, not until K2 Version 4.7 as I know).
Coming to example, I have Departments data (Department ID, DepartmentName) in K2 SmartBox
2.Departments
and Employees data in SQL Server

1.SQLData

Now we shall join the above data by creating a composite smartobject and execute it to see the result.
Step 1: Open Visualstudio, Create New K2 Empty project give it a name and in solution explorer right click add new smartobject and give it a name here it is (Employees) and click ok. Now at the top of window click AdvancedMode, under SmartObjectMethods click remove all and click ok

3.NewSmartObject

Step 2: Under SmartObject Methods, click on Add, Select AdvancedMode Checkbox and click next, provide a name and select list in Type Dropdown and click Next, Now in method parameters window click next as we can add parameters later while configuring,
Step 3: Now in ServiceObjectMethods window click Add and select the dbo.Employees table List method from the context browser under the SQL Server Service Instance

contextbrowser.jpg
Now Map the properties or simply click Create All to auto map the properties. Once done you should see below window

5.SQLServiceMethod
Click Ok and you should see the ServiceObjectMethod Window
Step 4: Again, Click Add and repeat the same steps for Departments.List which will be under K2 Smartbox Service instance once done click Ok

6.SmartBoxMethod
Step 5: Now we are at Service Method Link Window which is the main step of this SmartObject Creation. Here in first Dropdown select the Employees SQL Service Instance Method and in Link Type Dropdown select Matching Values in both objects and in 3rd dropdown select the Departments Smartbox Service method and in properties below, select DepartmentId and click assign and from the dropdown select DepartmentId and click ok.
Now we have joined SQL Server Employees Data with Smartbox Departments data using DepartmentId which is the common column in both data.
Link Type is kind of Join type as in SQL server. Here we have 4 different options of link types

Joins
1. Matching Values in both objects (similar to SQL Inner Join)
2. All Values for first object (Left Join)
3. All Values for Second object (Right Join)
4. All values for both objects (Outer Join)

Step 6: Just click ok and you are good to deploy and run the smartobject to see the results.
Result.jpg

Advertisements

Author: Vijay

I'm a K2 Certified Developer, helping teams to automate, design, develop & maintain business process applications connecting across multiple platforms with multiple technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s