K2 SmartObjects - Fundamentals

This learning module introduces K2 SmartObjects, describes how K2 SmartObjects can be used and explains how to create and use K2 SmartObjects

Contents

Module Overview ...... 4 SmartObjects in the K2 platform ...... 6 How SmartObjects work ...... 7 Common uses for SmartObjects ...... 9 When NOT to use SmartObjects ...... 12 Standard SmartObject Service Brokers ...... 14 SmartObject Abstraction: Data Types ...... 17 SmartObject Abstraction: Method Types ...... 19 SmartObject Property and Method Mapping ...... 20 Creating SmartObjects...... 22 Exposing SharePoint Lists and Libraries as SmartObjects ...... 29 LAB 1: Using K2 Site Settings to create SmartObjects for SharePoint lists ...... 30 Exposing other systems as SmartObjects ...... 32 LAB 2: Create SQL-based SmartObjects using K2 in SharePoint Central Administration ...... 33 Using SmartObjects in Workflows ...... 36 LAB 3: Using SmartObjects in workflow ...... 41 Using SmartObjects in Forms and Reports ...... 43 LAB 4: Using SmartObjects in an InfoPath Form ...... 45 REVIEW ...... 47 Additional Resources ...... 48

100.SYD Version: 2 Revision: 1

© SourceCode Technology Holdings, Inc. All Rights Reserved. 100.SYD - K2 SmartObjects - Fundamentals

The information contained in this document and its associated resources, including uniform resource locators and identifiers, is subject to change without notice.

Unless explicitly stated otherwise, the people, organizations, companies, places, domain names, e-mail addresses, products, logos, and events depicted are fictitious and no association with any actual people, organizations, companies, places, domain names, e-mail addresses, products, logos, and events is intended, or should be inferred under any circumstance.

SourceCode may have patents, patent applications, trademarks, copyrights, and/or other intellectual property rights covering all or part of the subject matter in this document and its associated resources. Except as expressly permitted by license agreement with SourceCode Technology Holdings, Inc. the furnishing of this document and associated resources, does not grant any license whatsoever to these patents, trademarks, copyrights, and/or other intellectual property.

This document and its associated resources are the sole property of SourceCode Technology Holdings, Inc. and SourceCode reserves all rights related to the information contained herein. Without limiting rights under copyright, no part of this document or its associated resources, may be reproduced, stored or introduced into a retrieval system, or transmitted in any form or by any means, without the prior written consent of SourceCode Technology Holdings, Inc.

Copyright © 2011. SourceCode Technology Holdings, Inc. All rights reserved. SourceCode software products are protected by one or more U.S. Patents. Other patents pending. SourceCode, K2, K2 blackpearl, K2 blackpoint, K2 connect, the four squares logo and K2 logotype are registered trademarks or trademarks of SourceCode Technology Holdings, Inc. in the United States and/or other countries

The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

Questions, Comments or Feedback about this training module? Please E-mail [email protected] with your comments or feedback. We appreciate any feedback that helps us to improve the quality of our learning material.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 2 100.SYD - K2 SmartObjects - Fundamentals

Conventions The following table documents the conventions used throughout this module: Convention Description

Bold Text With Border Represents commands, controls, items, menus, options, parameters, and file and folder paths. For example, in an instruction to click on the OK button; look for a control on the page with OK as its name. When you see text represented like this, you should see a control, window or field on the user interface with the same name.

Fixed-pitch font Represents text (or code) that must be entered exactly as shown. When you see text represented in this style, you should be typing this text into a textbox, control, code window or other UI component.

[Italic text in Square Represents variables or values to be selected from the K2 Context browser Brackets]

Fixed-pitch italic Represents additional instructions, explanations or a description of expected font behavior in Demonstrations and Lab Exercises

Represents a key to be pressed on the keyboard. For example, represents the Control key on the keyboard.

Represents a best practice. Best practices are the recommended approach or guidance for specific scenarios. When you see the Best Practice icon, consider how this practice impacts your requirements or how you can implement this practice in your environment.

Represents important information. Important information is highlighted in order to draw attention to a key piece of information, and typically serves as a warning or point you should bear in mind when using the K2 platform in your K2 solutions.

Represents a note. Notes explain a topic or provide additional information, and can provide a summary or explanatory point about a topic. Explains a concept, or a provides an explanation for a step in an exercise

Represents a hint, tip or available tools and resources that can help you during the design and development cycles of a K2 solution. Denotes technical information. This information is not vital in terms of meeting the goals of the learning module, but may be of interest to technical users. Represents trivia. The text included next to this icon is for interest only – think of it as a quick break from learning about K2.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 3 100.SYD - K2 SmartObjects - Fundamentals Module Overview

Module Overview This learning module introduces K2 SmartObjects, describes how K2 SmartObjects can be used and explains how to create and use K2 SmartObjects. This introductory module will cover the most common and fundamental use cases for SmartObjects. (Other K2 Learning modules will extend on the basic knowledge gained in this learning module.)

Target Audience This module is intended for business analysts, SharePoint power users and site administrators, developers and solution architects.

Outcomes At the end of this module, participants will have a good fundamental understanding of K2 SmartObjects and how these are created and used in real-world scenarios. .

Complexity This Module Level Definition 100 Introduction to the topic or overview and assumes little or no expertise with the topic being covered. Typically level 100 modules cover concepts, functions, features and benefits.

200 Covers intermediate learning materials and assumes 100-level knowledge and provides specific details about the topic and a fairly complete understanding of the features. 200-level training may discuss case studies that cover a breadth of common scenarios or explain how to use more advanced features.

300 Covers advanced learning materials and assumes 200-level knowledge, and an in-depth understanding of product features in a real-world environment. 300-level training provides a detailed technical subset of product

technologies that illustrate specific aspects of the product that are key to improving performance or interoperability and include architecture, performance, migration, development and deployment.

400 Expert learning materials and assumes a deep level of technical knowledge and experience, as well as a detailed, thorough understanding of the topic. 400-level courses are essentially expert-to-expert sessions and

the 400-level training content provides the means for customers to push products to maximum performance, achieve the broadest possible interoperability and create applications using the most advanced features.

Prerequisites and Required Knowledge This module requires basic knowledge the K2 platform. Completion of the learning module 100.SEA K2 Fundamentals is recommended before starting this learning module.

Compatibility This learning module is compatible with the following K2 products and versions Product Version Notes K2 blackpearl 4.6.5

Video A recorded version of this learning module is available online at http://help.k2.com/en/K2LV-100SYD.aspx. You will need an active K2 portal account to view this video.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 4 100.SYD - K2 SmartObjects - Fundamentals Module Overview

Virtual Environment Prerequisites This learning module has prerequisites which need to be configured to support the lab exercises. Follow the instructions below to set up the prerequisites for this learning module.

This script should be executed in the Virtual Server environment which accompanies this learning module.

Step Instructions Step 1: Tasks: Install the 1. Copy the file K2 Learning-100.SYD.exe provided with this learning module to any prerequisites for this training location in the Virtual Server environment. You may download the .exe file from the module in the K2 Learning Module Installers (Download) shortcut on the VPC desktop, or Virtual Server directly from the following URL: environment ftp://K2LearningInstallers:[email protected]/K2 Learning-100.SYD.exe Ask your instructor for help, if needed. 2. Double-click the file K2 Learning-100.SYD.exe to start the extract process. You A script is provided should extract the files to that will create all C:\K2 Learning (this value should be set correctly by default) the prerequisites for this module. 3. After the extract process has completed, double-click the file C:\K2 Learning\100.SYD\Setup\SetupPreRequisites.bat to install and deploy the prerequisites for this training module. The installation process may take up to 5 minutes to complete 4. Once you see the success message (Completed setting up prerequisites for learning module…) close the command window.

.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 5 100.SYD - K2 SmartObjects - Fundamentals SmartObjects in the K2 platform

SmartObjects in the K2 platform

SmartObjects in the K2 platform

Think of SmartObjects as an “Abstracted Data Access Layer”

You can think of K2 SmartObjects as an "Abstracted Data Access Layer" which exposes data and services from Providers (such as SQL databases, SharePoint lists and so on) to applications (such as Reports, Workflows and User Interfaces). SmartObjects are essentially a “middle layer” between sources of data (represented by the "Integration" block in the diagram above) and applications that require the data (represented by Workflows, Forms and Reports in the diagram above).

SmartObjects are in increasingly important component of the K2 platform, since they are primary data access mechanism for workflows, forms and reports. New product features like K2 SmartWizards also leverage SmartObjects, and doubtless the importance of this component will increase over time.

That said, it's not always necessary (or appropriate) to use SmartObjects. We will discuss the typical use cases and less-optimal use of SmartObjects in a following topic. Developers may still access LOB systems through code or other data access layers from K2 workflows, reports or user interfaces. Using SmartObjects just makes it much easier and quicker to implement solutions on the K2 platform.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 6 100.SYD - K2 SmartObjects - Fundamentals How SmartObjects work

How SmartObjects work

How SmartObjects work System-Specific “connectors” (Service Brokers)

K2 APIs/Services/Wizards

Think of K2 SmartObjects as a mechanism which exposes data and services from Providers (such as SQL databases, SharePoint lists and so on) to Consumers (such as Reports, Workflows and User Interfaces).

Consider the diagram in the slide above. On the left-hand side, we have providers (data sources such as SQL databases, web services, SharePoint lists and so on). On the right-hand side, we have consumers (applications like Reports, Workflows, SharePoint User Interfaces, K2 smartforms and developers.) Somehow, the consumers need to access data and services from the providers, and this is where SmartObjects come into play.

SmartObjects act as a translator (or “adapter”) which takes the complex nature or "language" of the Providers and converts the data and methods into an easy-to-understand, consistent interface that the consumers can understand.

Internally, this is achieved through the use of system-specific "connectors called Service Brokers (represented by the

icon) and consistent interfaces like services or wizards that are exposed by K2 (represented by the icon). This approach effectively abstracts the providers so that the consumers to do need to understand how to interact with the providers directly. Instead, the consumers “talk” to SmartObjects, and the K2 server takes care of the technical processing required to interact with the providers.

SmartObjects are an extremely powerful and flexible approach that allows designers and developers to interact easily with external systems. They can also act as an abstraction layer to create logical business objects that can combine data from multiple systems and represent them as simple-to-understand business objects. Consider the concept of an “Employee” business object. In the real world, employee data may exist in multiple systems (databases, , HR systems and more). A business user or workflow designer may not care about the location of the data that makes up an “Employee”, but they do need to be able to read Employee data into a workflow or report. This is where SmartObjects come into play: K2 can take care of all the integration and processing required to build up a logical “Employee” object from multiple data sources, and then present this logical object to the workflow or report designer so that they can use this data in their project.

Note that the communication is two-way. This means that SmartObjects can be used to both read and write information to the underlying systems. (Of course, authentication and authorization mechanisms are in place to ensure that only authorized users are allowed to read or update data )

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 7 100.SYD - K2 SmartObjects - Fundamentals How SmartObjects work

You should also note that SmartObjects is in itself not a data storage mechanisms and (with rare exceptions) the data is not stored or cached inside SmartObjects: the SmartObject is merely a "doorway" into the data provider and it’s the Provider which is ultimately storing the data.

K2 SmartObjects: Conceptual Representation

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 8 100.SYD - K2 SmartObjects - Fundamentals Common uses for SmartObjects

Common uses for SmartObjects

Common uses for SmartObjects  Data access in forms and reports  Primary data integration mechanism for K2 smartforms  Interact with external systems from workflows  Interface between K2 SmartWizards and data sources  Standardize data access mechanisms for development projects  Create a catalog of reusable business entities  Combine disparate data sources into logical, abstracted business entities  Externalize workflow business rules  Dynamic rules in workflows (destinations, start rules etc.)  Expose SmartObjects on SharePoint lists using BCS  Expose disparate external systems through standard APIs (e.g. K2 APIs and Web Services)

SmartObjects can be used in many different ways, but let's just cover the most common ways that SmartObjects are used in the real world

Data access in forms and reports Forms (User Interfaces) can also make use of SmartObjects. K2 provides forms technologies like K2 smartforms or integration wizards for third-party forms technologies like InfoPath, which allow forms designers to use SmartObjects in user interfaces..

SmartObjects can also be used when designing reports. K2 blackpearl provides a report design tool in the K2 Workspace, and other report design tools that support ADO.NET data sources (such as the SSRS Business Intelligence report designer in Visual Studio) can use the K2 ADO.Net Provider for SmartObjects to access data from providers, using SmartObjects as the "middle layer"..

Consider the importance of this example: SmartObjects make it possible to consume ANY data provider exposed as a SmartObject in a K2 smartform, InfoPath form or SSRS report, among many others. Need to combine data from Active Directory, SQL and a Web Service in a single report? That is easily possible using SmartObjects, as long as each of these sources has been “wrapped” as SmartObjects.

Primary data integration mechanism for K2 smartforms K2 smartforms is a K2 product used to create rich web-based user interfaces that can interact with various back-end systems through SmartObjects without requiring any code. The primary mechanism for SmartForms to interact with LOB system is through SmartObjects, and they rely heavily on SmartObjects.

Interact with external systems from workflows K2 workflow design tools such as K2 Designer for SharePoint, K2 Studio and K2 for Visual Studio provide visual wizards that allow designers to interact with SmartObjects easily. Of course, developers can still interact with external systems using assembly references and code, but the visual approach just makes the development of workflows much quicker, easier and more reliable. Note that before the wizards can be used, the required SmartObjects need to be created. This is where a repository of SmartObjects will become very useful to workflow, form and report designers.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 9 100.SYD - K2 SmartObjects - Fundamentals Common uses for SmartObjects

This approach is also used to separate data storage and workflow implementation. Rather than duplicating data in workflows, a workflow can access data from a provider in real-time using K2 SmartObjects.

These wizards allow developers to use SmartObjects in events, inline functions and rules such as line rules, destination rules, escalation rules and more, making it possible to create very powerful and flexible workflow solutions.

Standardize data access for development projects SmartObjects can be used to standardize all system integration and interaction in development projects (not only K2 Projects but custom code project as well). This approach makes it easy for workflow and form designers to make use of data and functions in external systems in their projects, since it is not necessary to learn the unique integration interfaces for each underlying system. The K2 design tools also make it easy for designers to interact with SmartObjects without needing to know anything about the underlying data provider.

Create a catalog of reusable business entities SmartObjects can be used to create a library or catalog of re-usable business entities or business objects. Consider the “Customer” business object. How often do applications need to access customer information? If the organization creates a logical “Customer” SmartObject, that same SmartObject can be re-used in multiple workflow, report and forms projects. This significantly speeds development delivery and simplifies support and maintenance.

Combine disparate data sources into logical, abstracted business entities SmartObjects can easily combine data from multiple LOB systems and represent that data as a logical entity. Consider an "Employee" object: in many organizations, the information that is relevant to an Employee is often spread out across many different systems. With SmartObjects, you can create a logical "Employee" business object which combines the data from all these systems and represents it as a single employee. Consumers do not know or care where the data comes from.

Externalize workflow business rules One of the recommended approaches when designing K2 workflows is to externalize business rules where it makes sense. Because the K2 design tools natively allow for the use of SmartObjects in multiple places, externalizing business rules into SmartObjects make it easy for designers to call the business rules in their workflows and for users to maintain these business rules outside of the workflow definition.

Here is an example: imagine that an expense claim workflow may need to decide on a path to take based on the total amount of the expense claim. For this financial quarter, if the expense claim total is more than $1,000, the claim must be sent for a second approval, but this “total amount” value changes every quarter. Rather than defining this limit as a static value in the workflow and having to update the workflow design every quarter, a SmartObject can be created which reads this value from a SharePoint list instead. The workflow will query this list whenever it needs to make the decision on sending for a second approval, and an authorized finance user can change this limit in the SharePoint list at any time without affecting the process design. .

Dynamic rules in workflows (destinations, start rules etc.) Similar to the externalized business rules approach described above, SmartObjects can be used to create dynamic rule evaluation in workflows. Almost all K2 workflow rule wizards allow for calling or using the results of SmartObject methods. Here are just a few examples:

. Set the destination users for an activity to the result of a SmartObject list method . Start multiple “child” processes from a “parent” process based on the result of SmartObject method (for example: start a sub-process for each line item in an invoice) . Set the start date for a specific step in a workflow based on the result of a SmartObject read method

Expose SmartObjects on SharePoint lists using BCS Since the introduction of SmartObject Services in K2 blackpearl update 1350, it has been possible to expose K2 SmartObjects on SharePoint lists using SharePoint’s Business Connectivity Services (BCS) technology. This makes it possible to expose almost any data source as a read or read-write SharePoint list. The K2 product documentation has more information on this approach.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 10 100.SYD - K2 SmartObjects - Fundamentals Common uses for SmartObjects

Expose disparate external systems through standard APIs (e.g. K2 APIs and Web Services) The K2 SmartObjects Services and the available K2 SmartObject APIs also make it possible to expose almost any data source consistently through the same interfaces. Imagine how much easier it is for developers to write code against a consistent API, regardless of the source of the data, rather than having to learn different APIs and access methods for different data sources.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 11 100.SYD - K2 SmartObjects - Fundamentals When NOT to use SmartObjects

When NOT to use SmartObjects

When NOT to use SmartObjects

 Very high-volume or high-load scenarios (e.g. high-volume OLTP)  Very low-latency scenarios  Enterprise Data Model Design  Message Bus/Transformation Engine for transactional data processing or ETL  Field-level security

The previous topic listed the most common uses and advantages of using SmartObjects. It may be tempting to think that of SmartObjects as a solution to all data abstraction and integration requirements, but there are certain scenarios where you should preferably NOT use SmartObjects. Although they may work in these scenarios in theory, in practice there are factors that would affect the viability of SmartObjects in these scenarios.

Very high-volume or high-load scenarios Because of the architecture of the SmartObjects framework, they are not ideally suited for very high-volume scenarios. For example, if you are building an online ticket processing system which needs be able to process tens of thousands of transactions per minute with low latency requirements, SmartObjects are probably not a good approach to use. While K2 is scalable and can handle a fair amount of load, it will not be suitable for scenarios where very high volumes are expected. In these cases, it is better to stick with the native data access mechanisms.

Due to the architecture and nature of SmartObject processing, it’s hard to give estimates on the upper limit of transactions that SmartObjects can handle: it depends a lot on the implementation of the underlying service broker the performance of the data provider and the communication speed between K2 and the provider. If you are expecting transaction loads of more than 10,000 transactions per minute, you should do some performance testing to verify whether the SmartObject implementation can handle the expected load. If you are expecting volumes in the range of hundreds of transactions per minute, it is still a good idea to do performance testing against a representative data set to get a realistic indication of the expected performance in the real world.

Very low-latency scenarios The architecture of the SmartObjects framework does not lend itself well to very low-latency requirements, for example scenarios where response times should consistently be under 100 milliseconds. If a system requires consistent response times of less than a few hundreds of milliseconds, it may be better to stick with native or direct data access. The processing that K2 server needs to perform to abstract and homogenize data from underlying systems into the logical SmartObject does add some processing time. It's hard to give a hard-and-fast rule, because the exact time will depend on the complexity of the SmartObject and the implementation of the broker. If you do have very low latency requirements and want to use SmartObjects, you should do some representative performance testing to verify that the response times are within range.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 12 100.SYD - K2 SmartObjects - Fundamentals When NOT to use SmartObjects

The processing time added by the K2 server depends on many factors, including (but not limited to) network latency, aggregation requirements, the filtering approach used for the broker and the current load of the K2 server. As a rule of thumb, processing time for a SmartObject should not exceed a few seconds at most. If it does, there may be an issue with the underlying broker or data source.

Enterprise Data Models Design Although SmartObject can be used to create a catalog or library of re-usable enterprise business entities/business objects, it is not intended to be a replacement for a dedicated Enterprise Data Model design. A better approach is to define and design the Enterprise Data Model in a tool of your choice, and then create the SmartObjects that implement the data model. While you certainly can use API calls to describe SmartObjects, it is not a very efficient approach if the data model is constantly queried.

As a Message Bus/Transformation Engine for transactional data processing or ETL Because of the performance overhead of the K2 SmartObjects framework, it is not recommended to use K2 SmartObjects as a message bus or transformation engine to achieve system integration or data processing. It is also not recommended to use SmartObjects for Extract, Transform and Load (ETL) type scenarios, since these normally involve moving large amounts of data which could add too much overhead to a K2 server which is also responsible for running K2 workflows at the same time. Although you CAN use SmartObject in this way, bear in mind the performance and volume restrictions we had mentioned before.

Field-level security K2 SmartObjects do not support field-level (or column-level) security. Although security configuration allows services to pass user credentials to an underlying provider, there is no concept of filtering available columns based on the current user. The closest approximation is if the provider returns empty values for the columns that are protected based on the current user.

If you are in doubt, K2 recommends using K2 Consulting Services or K2 Technical Advisory Services to help you determine whether SmartObjects is the right choice for your particular requirement.

Ultimately, a good rule to apply is to use the approach that makes the most sense. Using SmartObjects to allow workflows to integrate with external providers does not imply that you have to use SmartObjects for Forms and Reports as well. You could define SmartObjects and use them in workflows where response times are not as critical, but use native data access in user interfaces when very low latency is required.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 13 100.SYD - K2 SmartObjects - Fundamentals Standard SmartObject Service Brokers

Standard SmartObject Service Brokers

Standard SmartObject “connectors” (Service Brokers) Microsoft Products K2 Services . Active Directory (Write and Read) . K2 SmartBox . SharePoint (On-Premise and Online) . K2 Task Allocation . SQL Server databases . K2 User Role Management . SQL Server Reporting Services . SmartObject Service Description . Exchange Server . K2 Workflow Reporting (Generic and Solution-specific) . Dynamics CRM (On-Premise and Online) . K2 Workflow Runtime Interaction Other Products Generic Brokers . Salesforce.com . Assemblies . Oracle databases . WCF Services . SAP (When using K2 connect) . Web Services . PDF Converter

Note: Based on K2 4.6.5. Additional Service Brokers and version support for third-party products are added with K2 Product Updates, so check the update’s release notes!

The connector which exposes a data provider to the SmartObject subsystem is called a “Service Broker”. These service brokers are hosted in the K2 application server and are responsible for translating the provider’s native objects, properties and methods into the common “language” that K2 SmartObjects can understand.

K2 ships with several Out-of-The-Box Service Brokers that can expose common enterprise systems as SmartObjects without requiring any code. At most, it is only necessary to configure the providers to access a specific data source, after which SmartObject developers can create logical SmartObjects that interact with the data source.

The available standard services are listed below with explanatory notes, where applicable

K2 product updates often include new and enhanced service brokers, adding support for other third-party products or versions of third-party products. The Release Notes for the K2 product update will document any changes or additions to the set of standard service brokers.

Microsoft Products Product Notes Active Directory Provides read capabilities for Active Directory entities like Users, Groups and Organization Units. It is also possible to write into Active Directory to perform operations like . Create, update or disable a User Account . Add or remove users from groups . Create, update, or delete a group

SharePoint Provides capabilities to read, update, delete, list and add attachments to SharePoint items in Libraries and Lists. SharePoint On-Premise and Online implementations are supported. SQL Server databases Expose SQL database tables, stored procedures, and views as SmartObjects.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 14 100.SYD - K2 SmartObjects - Fundamentals Standard SmartObject Service Brokers

SQL Server Reporting Services Exposes the “Export” methods for reports published to a SSRS server as SmartObject methods, making it possible to generate reports and do something with the resulting file such as attaching it to an e-mail during a workflow. Exchange Server Exposes methods to interact with an Exchange server, such as . Create a new mailbox for a User in Exchange . Create a new Outlook Task . Send a new meeting request to one or more participants . Disable an existing mailbox in Exchange . Get Meeting Suggestions which will return potential meeting timeslots

Dynamics CRM Integration with Dynamics CRM, which gives the ability to create, update, delete and list both standard and custom entities stored in CRM. K2 Services Product Notes K2 SmartBox When using K2 blackpearl, this services provides a database for storing SmartObject data when there is no existing system that can store the data. K2 will automatically generate tables in this database to store SmartObject data. K2 Task Allocation Used to query reporting structures from Active Directory (e.g. Get Manager or “Get Direct Reports” and, when K2 Roles are used, perform task routing algorithms such as . Least Work . Most Work . Round Robin . Fastest User . Slowest User . Get Role Peers K2 User Role Management Provides methods for returning user, group and role information from the installed K2 Security Providers. K2 Workflow Reporting Provides the data used to generate the generic K2 workflow reports and also (optionally) exposes reporting SmartObjects for specific K2 workflow definitions in your K2 solutions. K2 Workflow Runtime interaction Provides runtime services for K2 workflows, such as starting new processes or opening and completing worklist items for specific events in the workflow.

Other Products Product Notes SalesForce.com Exposes salesforce.com entities for a specific SalesForce.com account using a WSDL provided by SalesForce.com This allows organizations to expose their SalesForce.com entities as SmartObjects. Oracle Databases Exposes tables, views and stored procedures in Oracle databases as SmartObjects SAP When K2 connect is installed with K2 blackpearl, SAP BAPIs can be exposed as SmartObjects, allowing for no-code consumption of SAP entities in workflows, reports and supported user interfaces. Note that K2 connect is a separate product and must be purchased in addition to K2 blackpearl should you wish to expose SAP entities as SmartObjects.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 15 100.SYD - K2 SmartObjects - Fundamentals Standard SmartObject Service Brokers

Generic Brokers Product Notes Assemblies Allows you to expose both static and instance methods of .NET assemblies, using both primitive and complex types. WCF Services Allows you to expose WCF services with primitive or complex types as SmartObjects Web Services Allows you to expose web services (e.g. .asmx services) as SmartObjects. PDF Converter Provides functions to convert Web Pages or HTML to PDF files.

It is also possible to extend the K2 platform to expose other data sources by creating and registering custom service brokers. This is typically a .NET developer task, and is discussed further in the learning module 400.BLR Custom Service Brokers

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 16 100.SYD - K2 SmartObjects - Fundamentals SmartObject Abstraction: Data Types

SmartObject Abstraction: Data Types

SmartObject Abstraction: Data Types Property Data Type Allowed Data Types Autonumber Auto-generating number (integer) AutoGUID Auto-generating globally unique identifier

Date Time Date and time

Decimal Decimal number

File File of any format

GUID Globally unique identifier

Hyperlink URI and description

Image Image of supported types

Memo A large text field containing ASCII text

Multivalue Proprietary XML used to display key value pairs

Number Whole number

Text A text field containing ANSI text characters

Yes/No Boolean, yes or no

One of the reasons why K2 SmartObjects can be used to expose different data sources consistently to different consumers is because the available data types for SmartObject properties are limited to specific types. Since the consuming applications will use standard K2 APIs to interact with the SmartObjects, they will already know how to consume the properties. The service broker is responsible for converting the SmartObjects properties into an equivalent data type that the provider understands.

The table below lists the possible data types that K2 SmartObjects properties may be

Type Allowed Data Autonumber Auto-generating number (integer)

AutoGUID Auto-generating globally unique identifier

Date Time Date and time

Decimal Decimal number

File File of any format

GUID Globally unique identifier

Hyperlink URI and description

Image Image of supported types

Memo A large text field containing ASCII text

Multivalue Proprietary XML used to display key value pairs

Number Whole number

Text A text field containing ANSI text characters

Yes/No Boolean, yes or no

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 17 100.SYD - K2 SmartObjects - Fundamentals SmartObject Abstraction: Data Types

When creating K2 SmartObjects using the K2 Design tools, the designer will define properties for the SmartObject, or may use the automatic generation features to create properties for a SmartObject. When using the K2 tools or utilities to generate SmartObjects, it is not necessary to specify the data types for each property; instead, the tools will automatically select the appropriate data type for each property of the SmartObject.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 18 100.SYD - K2 SmartObjects - Fundamentals SmartObject Abstraction: Method Types

SmartObject Abstraction: Method Types

SmartObject Abstraction: Method Types

Type Description Create Create a new record/row/instance (e.g. “Create new Customer”) Read Read single record/row/instance (e.g. “Load Customer Info”) Update Save/Update a record/row/instance (e.g. “Update Customer Info”) Delete Delete record/row/instance (e.g. “Delete Customer”) List Return many records/rows/instances (e.g. “List Customers”) Execute Execute a method call (e.g. “Disable Customer”)

Just like the standardized property types discussed in the previous topic, K2 SmartObjects methods types are also limited to a predefined set. This helps to make SmartObjects consistent and exposable though the same interfaces.

The available SmartObject method types are listed in the table below

Type Acts On / Returns Description Create Acts on a single SmartObject Create a new record/row/instance (e.g. “Create new Customer”)

Read Returns a single SmartObject Read single record/row/instance (e.g. “Load Customer Info”)

Update Acts on a single SmartObject Save/Update a record/row/instance (e.g. “Update Customer Info”)

Delete Acts on a single SmartObject Delete record/row/instance (e.g. “Delete Customer”)

List Returns one or more SmartObjects Return many records/rows/instances, potentially with filter criteria to limit the number of records returned. (e.g. “List Customers”)

Execute May return a single SmartObject Execute a method call (e.g. “Disable Customer”)

Just like SmartObjects properties, when using the K2 tools and utilities to generate SmartObjects, K2 will automatically select the appropriate method type for each SmartObject method. When designers and developers create K2 SmartObjects using the K2 design tools, they will need to specify the type of method being created.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 19 100.SYD - K2 SmartObjects - Fundamentals SmartObject Property and Method Mapping

SmartObject Property and Method Mapping

SmartObject Property and Method Mapping

A SmartObject is actually nothing more than a set of instructions that maps various properties and methods for a logical object to equivalent properties and methods in a data source, using a specific broker.

Refer to the diagram in the slide above (a larger version of this diagram is also provided on the next page). There is a data source on the left, and a SmartObject on the right. When SmartObjects are created, Property Mappings (indicated in a light blue color) will define how the various properties in the SmartObject will map to equivalent properties in the data source entity. Method Mappings will define how SmartObject methods will map to equivalent methods in the data source.

Consider the example SmartObject on the bottom half of the diagram. On the left-hand side, there is a SQL database table called CustomersTable. This table has several columns that contain customer information, and standard SQL statements like "Insert" or "Select" are used to interact with the data in this table. On the right-hand side, a SmartObject that represents a logical “Customer” has been defined. (This SmartObject definition is a XML-based file called Customer.sodx. This definition file is published to the K2 server, after which the SmartObject will be available for use in other projects.)

When the Customer SmartObject is created, the designer (or the auto-generation tool) will create and map properties of the SmartObject to the relevant columns in the SQL table, and specify appropriate data types for each property. (Note that the data types don’t match exactly in this example: it is up to the SQL service Broker to perform the necessary conversion between the two systems).

The SmartObject also has a set of methods (used by consumers to interact with the Customer object) and these methods are mapped using Method Mappings to the appropriate SQL statements for the database table. (Note that the Read and List methods both use the SQL “SELECT” statement, but Read expects only one row to be returned, while List expects one or more rows to be returned).

Ultimately, this combination of property and method mappings makes up the SmartObject definition - it’s as simple as that!

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 20 100.SYD - K2 SmartObjects - Fundamentals SmartObject Property and Method Mapping

Mapping SmartObject methods and properties

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 21 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

Creating SmartObjects

K2 provides several standard mechanisms for creating and publishing SmartObject definitions. Some of these tools can be used to automatically generate and publish SmartObjects, while the design tools are typically used to manually define and publish SmartObjects. Let’s look at each on a high level.

K2 Site Settings for SharePoint When K2 is installed in a SharePoint environment, site administrators, developers and SharePoint “Super Users” can use the K2 Site Settings feature to generate and publish SmartObjects for the document libraries and lists in the SharePoint site.

The following sequence of screenshots shows the basic process followed:

1. Accessing K2 Site Settings in SharePoint

2. Accessing the SmartObject generation screen for site lists and libraries

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 22 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

3. Selecting the lists and libraries to expose them as SmartObjects

Once the “Create” button is clicked, K2 will generate and deploy SmartObjects for each of the checked lists and libraries to the K2 server, and they will be available for use in workflows, forms and reports.

K2 for SharePoint in SharePoint Central Administration SharePoint administrators and developers can use the K2 for SharePoint features in SharePoint Central Administration to generate, export or import SmartObjects that represent Microsoft SQL database items (tables, views and stored procedures) and Microsoft Dynamics CRM entities.

Administrators can use the Data Management section of K2 for SharePoint section to define the connection settings for SQL or CRM and to select which entities should be exposed as SmartObjects. They may also import and export SmartObject configurations form this interface.

Creating SQL and CRM SmartObjects in SharePoint Central Administration

K2 SmartObject Tester Utility The K2 SmartObject Tester is a utility application most commonly used by K2 Administrators and Developers to generate and deploy K2 SmartObjects. This utility has many useful features for creating, importing and exporting, testing and creating code for SmartObjects, and we’ll investigate those more closely in another learning module.

This utility is installed in the following location when the K2 blackpearl components (client or server) are installed: [K2 Installation Directory]\Bin\SmartObject Service Tester.exe (for example C:\Program Files (x86)\K2 blackpearl\Bin\SmartObject Service Tester.exe) © SourceCode Technology Holdings, Inc. All Rights Reserved Page 23 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

Creating a SmartObject using the K2 SmartObject Tester utility

The K2 SmartObject Tester is an extremely useful tool for creating, testing and generating code for SmartObjects. If you are a developer you should add this utility to your toolset; it will be a very useful resource when you are developing or working with SmartObjects. You will learn more about using this tool in the module 200.PER K2 SmartObjects - Intermediate

K2 Studio K2 Studio is a design environment that is typically used by Business Analysts and Developers to manually define SmartObjects and deploy them to a K2 environment (or create a deployment package for later deployment).

This design environment allows users to create advanced SmartObjects, such as composite SmartObjects that combine data from different data sources, lookup SmartObjects and to define relationships between SmartObjects. We will cover the manual creation of SmartObjects and advanced SmartObjects in the learning module 200.PER K2 SmartObjects – Intermediate.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 24 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

Launching K2 Studio

Creating a new SmartObject in K2 Studio

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 25 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

Defining SmartObject Properties and Methods in K2 Studio

K2 for Visual Studio K2 for Visual studio is an add-in for , and is typically used by developers to create and publish (or create deployment packages) SmartObjects. This environment is very similar to the K2 Studio design tool, but since it runs inside Visual Studio developers can take advantage of Visual Studio’s built-in solution management and source control features. It also allows developers to create an entire project in the Same Visual Studio solution, including workflows, SmartObjects, forms, reports and everything else that makes up the solution.

Creating a new K2 SmartObject project in Visual Studio

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 26 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

Defining SmartObject Properties and Methods in Visual Studio

K2 Designer When K2 smartforms is installed, a web-based design environment known as K2 Designer can be used to design and deploy K2 SmartObjects. Just like the K2 Studio and K2 for Visual Studio tools, Business Analysts and Developers can use this design environment to create both simple and complex SmartObjects targeting any available service brokers in the K2 environment. This design environment is described more in the K2 Learning modules 100.YYZ K2 smartforms – Fundamentals and 200.YUL K2 smartforms - Intermediate

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 27 100.SYD - K2 SmartObjects - Fundamentals Creating SmartObjects

Editing a SmartObject in K2 Designer

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 28 100.SYD - K2 SmartObjects - Fundamentals Exposing SharePoint Lists and Libraries as SmartObjects

Exposing SharePoint Lists and Libraries as SmartObjects

Exposing SharePoint Lists and Libraries as SmartObjects

 SharePoint Lists and Libraries can act as a data source for SmartObjects  It’s easy to create the data store since SharePoint super-users are already familiar with creating custom lists and libraries  Use K2 Site Settings to expose selected lists and libraries as SmartObjects  Data in SharePoint can then be used by multiple other consumers  SharePoint provides standard User Interfaces for interacting with the data

SharePoint lists and libraries are a common approach for custom data storage that can be created and maintained by developers and non-developers alike. SharePoint “super”-users are probably already familiar with creating lists, custom lists and document libraries in SharePoint. These lists and libraries can easily be exposed as SmartObjects using K2 Site settings. Once this is done, those lists and libraries can be consumed by any application that understands how to interact with SmartObjects.

As an added bonus, SharePoint provides standard user interfaces for interacting with SharePoint lists, so there is no need to create many additional forms so that users can interact with the data. In addition, if a list uses Business Connectivity Service (BCS) to expose data from external systems in SharePoint, that list can easily be converted to a K2 SmartObject so that the data can be used in SmartObject consumers like K2 workflows, InfoPath forms or SSRS reports.

From a workflow business rules perspective, a common use is to allow the business to define and maintain business rules in a SharePoint list (defining task routing conditions or approval limits, for example). That list is exposed as a SmartObject so that it can be used in a workflow. At runtime, the workflow will always query the list and will then execute accordingly. This approach allows the business to maintain their business rules outside of the workflow through familiar interfaces.

Exposing business rules as SmartObjects, regardless of the underlying data store, makes it easy for workflow developers to consume the rules and easy for business to maintain the rules.

In the next lab exercise, you will learn how to use K2 Site Settings to expose Lists as SmartObjects. This isn’t the only available mechanism though: remember that SharePoint is just another data source as far as K2 is concerned. Designers and developers are also free to use the available K2 blackpearl design tools or utilities to create customized SmartObjects that leverage SharePoint lists or libraries as their data source.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 29 100.SYD - K2 SmartObjects - Fundamentals LAB 1: Using K2 Site Settings to create SmartObjects for SharePoint lists

LAB 1: Using K2 Site Settings to create SmartObjects for SharePoint lists

LAB 1: Using K2 Site Settings to create SmartObjects for SharePoint lists

In this lab you will create and deploy a SmartObject based on a SharePoint list using the K2 Site Settings feature in a SharePoint site

5 minutes

Objective In this lab, you will use K2 Settings in a SharePoint site to create and deploy SmartObjects that expose a SharePoint list. This lab will cover the following concepts:

 How to use K2 Site Settings to create SmartObjects based on SharePoint lists

Duration This lab has 2 steps and should take around 5 minutes to complete.

Context Denallix has a requirement to store a list of Asset Managers per Department. The purpose of this list is to assign the responsibility of asset management to a specific user in each department. (As an example, this list could be used during asset management workflows to assign tasks to each departmental asset manager.) A SharePoint list was selected since this makes it easy for the business to maintain the departmental asset managers without requiring any assistance from IT.

There is also a requirement for users to schedule asset audits, so another list called 100SYD Asset Audits was created. This list will be used to schedule asset audit workflows to start at some date in the future. You will learn how to use these lists in workflows in another lab exercise: for now, let's just create SmartObjects for the lists so that they are available for use when designing workflows.

Additional Notes You may have noticed some additional settings when creating the SmartObjects:

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 30 100.SYD - K2 SmartObjects - Fundamentals LAB 1: Using K2 Site Settings to create SmartObjects for SharePoint lists

Security If this option is checked, K2 will interact with the list under the context of the connected user account. If this is not checked, K2 will always interact with the list under the context of the K2 service account. If this list is security-sensitive or uses item-level security, you probably want to check this option so that whenever users use a report or form to query the list, they will only see those items in the list that they have permission to see. If a workflow accesses the list the security context is usually the K2 Service account, unless the event has been set to execute under another user’s credentials.

Dynamic This option will add an additional property to the generated SmartObject that will require a URL to be passed for the site where the list is located. This option is used if you have used the same list template to create lists in separate sites. By requiring a parameter for the site URL, you can re-use one SmartObject to interact with the different lists on the different sites, as long as those definitions for the lists are the same

Advanced This option is used when you want to define the methods and properties for SmartObjects that interact with site manually. Essentially, this option "registers" the SharePoint site as a data source on the K2 server, and you can then use the manual SmartObject design tools like K2 Studio or K2 Designer to create simple or composite SmartObjects for the lists and libraries in the site. (Note that this option is only really usable in K2 blackpearl)

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 31 100.SYD - K2 SmartObjects - Fundamentals Exposing other systems as SmartObjects

Exposing other systems as SmartObjects

Exposing other systems as SmartObjects

 K2 supports several “connectors”/service brokers as standard . Microsoft products like SQL Server, SSRS, Dynamics CRM, Active Directory, Microsoft Exchange . Other products like salesforce.com, Oracle and SAP  Developers can create custom brokers to expose non-supported systems as SmartObjects . Covered in module 400.BLR Custom Service Brokers  Creating SmartObjects that interact with other systems . K2 for SharePoint in SharePoint Central Administration (SQL and CRM only) . K2 Studio and K2 for Visual Studio . K2 Designer (if SmartForms is installed) . K2 Tools and Utilities (e.g. SmartObject Service Tester utility)

SharePoint lists and libraries are not the only data source that can be exposed as K2 SmartObjects. As mentioned earlier in this learning module, K2 provides several standard Service Brokers which enable K2 to use common enterprise applications as the provider of SmartObject data and methods. Some of the more common systems that can be exposed as SmartObjects include:

. Microsoft SQL Server (tables, views and stored procedures) . Microsoft SQL Server Reporting Services . Microsoft Dynamics CRM . Microsoft Active Directory . Salesforce.com . Oracle databases (tables, views and stored procedures) . SAP (requires K2 blackpearl with K2 connect)

There are many other adapters available for other systems and K2 adds support for other products and new versions of products with product updates. K2 blackpearl also allows developers to extend K2 with custom service brokers so that other systems can also be exposed as SmartObjects. The learning modules 200.PER K2 SmartObjects – Intermediate and 300.MLB K2 SmartObjects – Advanced discuss these approaches in more detail.

Designers and developers have several tools at their disposal to create SmartObjects based on any of the available providers:

. SharePoint Administrators can use the K2 for SharePoint section in SharePoint Central Administration to generate SmartObjects based on Microsoft SQL databases and entities in Microsoft Dynamics CRM. . K2 Studio and K2 for Visual Studio are used to define simple and advanced SmartObjects with full control over the naming, properties and methods that the SmartObjects will expose. . K2 blackpearl provides additional tools and utilities like the K2 SmartObject Service Tester that can be used to generate and test SmartObjects

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 32 100.SYD - K2 SmartObjects - Fundamentals LAB 2: Create SQL-based SmartObjects using K2 in SharePoint Central Administration

LAB 2: Create SQL-based SmartObjects using K2 in SharePoint Central Administration

LAB 2: Create SQL-based SmartObjects using K2 in SharePoint Central Administration

In this lab you will create SQL-based SmartObjects for tables in an existing SQL database using K2 for SharePoint in SharePoint Central Administration

5 minutes

Objective In this lab, you will use K2 for SharePoint in SharePoint Central Administration site to create and deploy K2 SmartObjects based on specific tables in a SQL database.

Duration This lab should take around 5 minutes to complete.

Context Denallix has a SQL database that is used to store certain organizational data such as customers, employees, departments, assets and so on. We want to expose selected tables in this database as SmartObjects so that workflow designers, form designers and report designers can use these SQL tables in their solutions.

In this exercise you will use the SharePoint Central administration console to generate SmartObjects for selected tables in the K2Learning sample database.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 33 100.SYD - K2 SmartObjects - Fundamentals LAB 2: Create SQL-based SmartObjects using K2 in SharePoint Central Administration

Additional Notes You may have noticed some additional settings when defining the SQL connection:

The first set of credentials (SQL Settings) are the credentials K2 will use at runtime to connect to the SQL database and execute the SmartObject methods (for example, deleting records from the database with a Delete operation, or updating data with a Save operation). Depending on your environment, you may want to always use the connected user’s credentials (Impersonate the User Account), always use the K2 Service Account or specify a SQL user account to use when interacting with the database at runtime. The simplest option is to use the K2 Service account or the specified account, and to ensure that these account have sufficient rights to perform the operations in the SQL database. If your database uses security to control access based on the user (typically with Integrated Security and SQL security and permissions settings), you may want to use the Impersonate option so that the currently-connected user’s credentials are always used when K2 performs and operation against the SQL database. This will help prevent unauthorized access or modification of data through SmartObjects.

The second set of credentials (Design Time Credentials) allows you to provide credentials for discovering the available items in the SQL database. Let’s assume that the current user (the SharePoint administrator) does not have sufficient security access to the target database to connect to it and list the available tables, but the K2 service account does. The administrator can tell K2 to use the K2 service account to discover the available tables, views and stored procedures in the database at design-time only. At runtime, K2 will use the first set of credentials.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 34 100.SYD - K2 SmartObjects - Fundamentals LAB 2: Create SQL-based SmartObjects using K2 in SharePoint Central Administration

The other option you may have noticed is the advanced setting when selecting the SQL items to expose as SmartObjects:

This option will allow you to select which columns of data should be included in the generated SmartObject and allows you to rename the properties for the SmartObject so that it is easier for designer to understand what they are working with. Here is an example of the advanced screen for the Customer table, where we selected only certain columns and renamed some of the properties

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 35 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Workflows

Using SmartObjects in Workflows

The K2 Workflow design tools (K2 Designer for SharePoint, K2 Studio, K2 for Visual Studio and K2 Designer) allow workflow designers and developers to use SmartObjects in various ways while assembling a process. Here are the most common ways SmartObjects are used in workflows:

SmartObject Event Wizard The SmartObject Event Wizard can execute any SmartObjects method, and designers can provide the necessary input parameters for the SmartObject from any data field, context field, hardcoded value or even another SmartObjects method. As an example, perhaps a customer onboarding process requires approval for the discount percentage offered to the customer. If this discount is approved by the sales manager, the K2 workflow will use a SmartObject event to update the customer’s discount percentage in the Sales database.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 36 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Workflows

Using the SmartObject Event wizard

Inline Functions Inline Functions can accept SmartObject return values as input parameter as well. Here is an example: perhaps a new employee’s domain login name should be their [email protected]. As part of the employee onboarding workflow, we can use text manipulation functions like Join and Left to extract the necessary characters from the employee’s name, combine these datafields, save the result into a process datafield, and use this generated value later on in the workflow when the AD account is created. The employee's name, in turn, could have been provided by a SmartObject method like Employee.Read

Using a SmartObject property in a Inline Function

Data Event wizard The data event wizard is most commonly used to set the value of a data field in a process, but the wizard allows you to drag in SmartObject methods for both the Source and Destination fields.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 37 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Workflows

Setting the Process Folio to a SmartObject property

This wizard is very useful when you want to query data from somewhere and save the result into a process variable/datafield so that it can be used later on in the workflow.

Use the result of SmartObject Methods to control workflow execution Apart from the mechanisms mentioned above, the K2 design tools also allow designers to use the results of SmartObject methods in various places of the workflow design. This feature makes it possible to create very dynamic and adaptive processes, and can help to simplify a process design significantly. Here are some of the most common ways SmartObjects are used to control process execution

Wizard/Rule Example of use Wizard Insert a property from a SmartObject method into any wizard textbox. Textboxes Example: retrieve the customer’s primary email address from a database and then use this email in the To line of the e-mail event wizard, or use a SmartObject method to dynamically build up the Body of an e-mail

Using a SmartObject property in the e-mail wizard

Destinations/ Set the destination/participants for a specific user step in the workflow to the result of a Participants SmartObject method. (Note: This works for lists of items as well, so you can assign a task to multiple users in the same Destination setup)

Example: You have a SmartObject based on a SharePoint list, and the list stores a list of task types along with users who can perform that type of task. In the destination rule of a workflow, you execute the List method and pass in a filter of the type of task being performed, which returns a list of user names for all the users who can perform that particular task. Set the destination of the task to this list of user names so that K2 will create a task for each of the users returned from the SharePoint list.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 38 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Workflows

Using a SmartObject in a Destination rule

Destination Use a SmartObject method to determine a True/False result, which decides whether a task Rules/ should be allocated to a particular Task Group or Destination Set. Task Groups Example: you have a step in a customer complaint process where someone must respond to a customer complaint. Using the Customer SmartObject, we will retrieve the customer’s annual sales total from the sales database. If the annual sales exceed a specific amount, the task will be assigned to the Priority Customer Care task group; otherwise the task will be assigned to the standard Customer Care task group.

Preceding Rules Use a SmartObject method to determine a True/False result which decides whether a particular activity should even start.

Example: at the end of a customer sales order process, we may randomly want to start a customer follow-up sub-process. You could create a SmartObject which will return a True/False value based on some random calculation, and if the value is True the sub-process will be started, otherwise the sales order process just ends.

Start Rules Use a SmartObject to return a date/time or integer value which is used to determine the start date for an activity.

Example: in an Employee Annual Review process, the annual review should be scheduled at the anniversary of the employee’s start date with the company. Using a SmartObject, you can look up the start date of the employee in a database and then set the Start date for the review task to the same date of the current year.

Escalations Use SmartObject properties to set both the start date of the escalation as well as the escalation action.

Example: in a customer work-order workflow, the workflow should set the escalation date based on the customer’s SLA. You can use a SmartObject to calculate the start date for the escalation based on the customer’s SLA.

In the escalation action you can also use a SmartObject property. For example, use a SmartObject to retrieve the customer’s account manager, and then email the account manager as well as the team leader if the customer’s SLA is about to be breached.

Succeeding Use SmartObjects to decide whether a step in the workflow is allowed to complete. Rules Example: perhaps a voting scenario in a change management process requires different approval percentages based on the type of issue being voted. A high-impact change requires 80% approval while a low-impact change only requires 60% approval. You could use a SmartObject property to calculate the number of approval responses required for the impact

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 39 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Workflows

level of the proposed change. Once the required level is reached the remaining tasks can be expired and the process can continue.

Line SmartObjects can also be used to establish True/False results which will determine whether a Rules/Outcomes particular path of the process is followed. This is most commonly used to control the flow of a process dynamically.

Example: in a press release workflow, any press releases relating to financials must be reviewed by the Finance department; otherwise the release can be published right away. In the workflow, you could use a SmartObject to read the type of press release being issued, and if the type is “Financial Statement” or “Annual Report”, the process should go to the Finance Review task. Using a SmartObject property in a Line Rule comparison rule

You should be starting to understand the power of SmartObjects in workflows. Using SmartObjects allows you to create very powerful, flexible and dynamic processes that can interact with almost any data provider in various ways. In the next exercise you will see just a few ways that SmartObjects can be used in workflow, and other learning modules will illustrate even more mechanisms. What is most important right now is knowing that SmartObjects can make workflows powerful and flexible.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 40 100.SYD - K2 SmartObjects - Fundamentals LAB 3: Using SmartObjects in workflow

LAB 3: Using SmartObjects in workflow

LAB 3: Using SmartObjects in Workflow

In this lab you will learn how to use K2 SmartObjects in workflows, both to define workflow rules (for example, start rules and destination rules) and directly though the SmartObject event wizard

20 minutes

Objective In this lab, you will use K2 SmartObjects in a K2 workflow. You will learn how to call SmartObject methods when designing workflow rules and how to use the SmartObject event wizard to interact with SmartObjects directly as a workflow event.

Specifically, this lab illustrates the following concepts:

 Using a SmartObject property to define a Start rule for an activity  Using a SmartObject list method to determine a list of participants for a workflow step  Using a SmartObject event wizard to update a SmartObject during a workflow

Duration This lab has 2 parts and should take around 20 minutes to complete.

To save time, a semi-completed workflow project has already been created for you. You will modify this existing project with required SmartObject integration.

Context Denallix wants to use the Assets SmartObjects you created in the previous exercises to control asset audit processes. Three SmartObjects will be used in this process:

Asset Audits This list is used to register new Asset Audit processes. When a new item is created in this list, an asset audit process will be started, and the departmental asset managers will receive an asset audit task. Once all the departmental asset managers have completed their tasks, the Audit Completion Date column for the current audit will be updated with the audit completion date. You will use the Audit Start Date column to determine when the audit task should be delivered to each departmental asset manager. You will use the Read method for the SmartObject based on the 100SYD Asset Audits list to retrieve the start date..

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 41 100.SYD - K2 SmartObjects - Fundamentals LAB 3: Using SmartObjects in workflow

You will use a SmartObject event to update the Audit Completion Date for the Asset Audits SmartObject when the workflow completes.

Departmental Asset Managers This SharePoint list will be used to deliver asset audit tasks to the designated departmental asset managers. Every time a Departmental Asset Audit activity is started, the asset manager for each department will get a task to perform the asset audit.

You will use the List method for the 100SYD Departmental Asset Managers to determine the users who will perform the audit task, and use this task the destination rule of the activity Departmental Asset Audit

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 42 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Forms and Reports

Using SmartObjects in Forms and Reports

SmartObjects can also be used in Forms and Reports. Let’s look at the most common ways this is done.

K2 SmartForms SmartObjects are the default data access mechanism used in K2 SmartForms. Using SmartObjects makes it very easy for designers to create rich user interfaces with integration into LOB systems. These user interfaces can be accessed through most web browsers and the integration with the LOB system is seamless and transparent.

InfoPath Any SmartObject method can be added as a data source to an InfoPath form. K2 provides an integration wizard that will take care of registering the SmartObject method as a data source on the form. All the form designer needs to do is decide when to use the data source in the form; typically by defining rules on the form. The lab exercise that follows will show you how this is done.

If you are familiar with InfoPath, you probably know that forms can be published to a SharePoint environment and be rendered using the browser. The K2 SmartObjects will still work in these scenarios, making it possible to create web- based forms with rich data interaction capability without writing any code.

K2 Generated Pages SmartObject methods and properties can also be exposed on K2 generated pages which are generated by the Forms Generation Client event in the workflow design tools. This is most often used to populate data on forms, or to populate drop-down lists on forms when lookup SmartObjects are defined.

Code Developers can interact with SmartObjects through any of the available SmartObject APIs. These include the SmartObject Client API, the auto-generated WCF endpoints for SmartObjects (which can be consumed by any code capable of interacting with WCF services) and the K2 ADO.NET provider for SmartObjects. By using code, developers can then expose SmartObjects on almost any user interface: windows applications, custom web forms, mobile applications and more.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 43 100.SYD - K2 SmartObjects - Fundamentals Using SmartObjects in Forms and Reports

SharePoint By leveraging the generated SmartObjects WCF services, SmartObjects can be exposed on SharePoint lists using Business Connectivity Services (BCS) or Business Data Catalog (BDC) in SharePoint 2007 environments. SharePoint automatically generates user interfaces for these lists, which means that it is easy to create lists and user input forms for any data source that can be exposed as a SmartObject without writing any code.

Reports Report designers can also use SmartObject’s as data sources when designing reports. Apart from the custom report design tool available in the K2 Workspace, any report designer that is capable of referencing an ADO.NET provider can be used to create custom reports against any SmartObjects. Most often, Microsoft Report design tools such as Report Designer or Business Intelligence Studio are used to create SSRS-based reports that utilize SmartObjects. These design tools use the available K2 ADO.NET provider to interact with SmartObjects.

A powerful feature of this approach is that it becomes possible to combine data from different data sources in one report. For example, if you have SmartObjects that list data from Active Directory user accounts and SmartObjects that list data from a SQL database, it is possible to combine these two data sources in one report. This approach is discussed more in the learning module 300.UKY Creating Custom Reports with Report Design Tools.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 44 100.SYD - K2 SmartObjects - Fundamentals LAB 4: Using SmartObjects in an InfoPath Form

LAB 4: Using SmartObjects in an InfoPath Form

LAB 4: Using SmartObjects in an InfoPath Form

In this exercise you will learn how to use SmartObjects in an InfoPath form. (InfoPath is just one of the possible User Interface technologies that can integrate with SmartObjects)

In this scenario, you will add a SmartObject to an existing InfoPath form to list Asset information from a SQL database

10 minutes

Objective In this exercise you will learn how to use SmartObjects as a data source in an InfoPath form. (InfoPath is just one of the available forms technologies you can use to present SmartObject information to users. You could also use K2 smartforms, K2 Generated pages, ASP.NET forms or .NET code to create user interfaces that display SmartObject data. The purpose of this exercise is just to show one of the possible technologies you can use to expose SmartObjects. Other Learning modules will describe the other approaches in more detail)

This lab demonstrates the following topics  How to add SmartObjects as a data source to an InfoPath form and how to populate the InfoPath form with data from a SmartObject.

Duration This lab has should take around 10 minutes to complete. You will create a form to display information from a SQL database and preview the form to test the data retrieval

Context Denallix wants to create a user interface to show information about the assets in the organization. All the information required exists in a SQL database.

In Lab exercise 2 of this module, you created a set of SmartObjects for the K2Learning SQL database. We will use one of those SmartObjects ([Denallix].[Assets]) in an InfoPath form for this exercise. Because of time constraints, we will only create a single view of the form which lists information in the asset register table. It is just as easy to create input forms that could write or modify data in the SQL database using the same principles, and other Learning modules will cover that in more detail.

Practical Application of this lab Remember that SmartObjects can expose almost any data source, and can combine data from different data sources into a single logical business object. Microsoft InfoPath is a user-friendly form design tool, and the integration capabilities provided by K2 effectively means that users and form designers can easily create user interfaces that interact with any systems exposed as K2 SmartObjects.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 45 100.SYD - K2 SmartObjects - Fundamentals LAB 4: Using SmartObjects in an InfoPath Form

This particular lab was a very simplified example, but this same approach can be used to build rich user interfaces for data capture, update and retrieval. What’s more, InfoPath form templates can be published to SharePoint as web- based forms, which means that designers can create web-based forms that integrate with any system exposed as a SmartObject without needing to write a line of code, and without developer assistance.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 46 100.SYD - K2 SmartObjects - Fundamentals REVIEW

REVIEW

Review and Q&A

 SmartObjects overview  Common uses for SmartObjects  When not to use SmartObjects  Standard SmartObject Services  How to create SmartObjects  Using SmartObjects in Workflows  Using SmartObjects in Forms and Reports

This learning module provided you with fundamental knowledge about K2 SmartObjects, described how they are used and how they are created.

Let’s review the main topics discussed in this learning module:

. SmartObjects overview . Common uses for SmartObjects . When not to use SmartObjects . Standard SmartObject Services . How to create SmartObjects . Using SmartObjects in Workflows . Using SmartObjects in Forms and Reports

Consider how these topics apply to your requirements and to your environment. Can you identify possible data sources you may want to expose as K2 SmartObjects so they can be re-used in K2 solutions, user interfaces or reports? Feel free to discuss your requirements with the instructor or within the group, if time permits.

This is also your opportunity for asking questions to clarify any of the topics covered during this module. Following modules will build on the knowledge you gained in this module, so if you are unclear about a topic, please do ask the instructor to explain or elaborate.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 47 100.SYD - K2 SmartObjects - Fundamentals Additional Resources

Additional Resources The following table lists additional resources that supplement the information provided in this module:

Resource Location and Notes How To: Working with K2 Exchange http://help.k2.com/en/KB001189.aspx Integration Describes how to use Microsoft Exchange server integration using K2 SmartObjects and K2 workflow Event Wizards

K2 Product Compatibility Matrixes Lists the compatibility of K2 products with various technologies and supporting systems

http://help.k2.com/en/blackpearlmatrix.aspx Compatibility matrix for K2 blackpearl

Random fact: The unusual and provocative shapes of the Sydney Opera house in Sydney, Australia are based on a simple concept: according to the architect (Bjorn Utzon), his design was inspired by the simple act of peeling an orange: the 14 shells of the building, if combined, would form a perfect sphere.

© SourceCode Technology Holdings, Inc. All Rights Reserved Page 48