Building a K2 Smartform spider part 2

Taking part 1 further

So in part 1 we looked at a couple of basic methods for getting a list of  Smartforms and Views that are currently on the K2 Server. Which can be really handy if you wanted to build a library of all your forms and views.

But can take this further? We can already from the K2 designer expand the form and see what views make up that form, but we can’t though click on a view and see what forms it is being used in.

Finding all forms for a selected view

So in this section I am going to go through how we can retrieve a list of all the forms that a view has been used in. It pretty much uses the same code as the previous examples except this time we will be using  some additional methods that come with the API.

public List<SmartFormView> GetAllFormsForView(string viewName)
var list = new List<SmartFormView>();
var frm = new FormsManager(servername, port);
FormExplorer formexplorer = frm.GetFormsForView(viewName);
foreach (SourceCode.Forms.Management.FormInfo forminfo in formexplorer.Forms)

list.Add(new SmartFormView
name = forminfo.Name,
displayname = forminfo.DisplayName,
description = forminfo.Description,
guid = forminfo.Guid,
version = forminfo.Version,
CheckedOutBy = forminfo.CheckedOutBy,
theme = forminfo.Theme.ToString()

return list;


So you can see from the code above , its practically the same as just looping through all the forms. The only difference is this method call


All we do is call the above method and pass in the name of the view and we can then loop through all the forms  where that view is being used.

Finding all views for a selected form

So as we have done this for the view, it would only be fair if we did this for the form and like the example above it is very similar to the examples in part 1.

public List<SmartFormView> GetAllViews(string formname)
List<SmartFormView> list = new List<SmartFormView>();
FormsManager frm = new FormsManager(servername, port);
ViewExplorer formexplorer = frm.GetViewsForForm(formname);
foreach (SourceCode.Forms.Management.ViewInfo viewinfo in formexplorer.Views)

list.Add(new SmartFormView
name = viewinfo.Name,
displayname = viewinfo.DisplayName,
description = viewinfo.Description,
guid = viewinfo.Guid,
version = viewinfo.Version,


return list;


If we look at the code above the only difference is the method that is being called


We call this method and pass in the name of the form, or even the GUID and it then returns a list of all the views that are in the form.

Other methods

We can take this even further  and we can get a list of views that is being used by  a SmartObject and even a  list of views/forms that is calling a specific workflow

GetViewsForObject(Smartobject GUID)

GetViewsForProcess(Process Name)

GetFormsForProcess(Process Name)


In part 3 we will take these a bit further and drill down into the views and forms to see what makes up those artifacts.

I will make the source code available at the end of this series.

2 thoughts on “Building a K2 Smartform spider part 2

Leave a Reply

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

You are commenting using your 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