Building a K2 Smartform spider part 3

In part 1 we looked at how to get a list of all the Smartforms and views on the K2 server and in part 2 we looked how we could filter those lists by finding all the forms that particular view has been used in etc..

In part 3 we will look at how to go deeper into those artifacts with out actually having to open up the artifact in edit mode to see whats go on.

Getting started

To get started we need some additional objects that are not available in the standard properties that is found in part 1. We need to get  access to the definition of the artifact (basically the XML).

Some of the objects that we will be able to access are

  1.  Properties
  2. Controls
  3. Parameters
  4. Events

To access these additional objects we need to use the following line of code.

Code for a Smartform

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(‘form name’));

Code for a view

SourceCode.Forms.Authoring.View view = new SourceCode.Forms.Authoring.View(frm.GetViewDefinition(‘View Name’));

Parameters

So lets start with an easy one and get the list of parameters that are available on that particular view.

Getting a list of parameters for a form

The below method gets a list of all the parameters for a form

public List<SmartFormViewParameters> ArtifactParameters(SourceCode.Forms.Authoring.FormParameterCollection parameters)
{
List<SmartFormViewParameters> list = new List<SmartFormViewParameters>();
foreach (SourceCode.Forms.Authoring.FormParameter parameter in parameters)
{
list.Add(new SmartFormViewParameters {
name = parameter.Name,
type = parameter.DataType.ToString(),
defaultvalue = parameter.DefaultValue
});
}

return list;

}

The method has the input parameter of type ‘parameter collection’ which we can using the code the code from the ‘Getting Started’ section.

SourceCode.Forms.Authoring.FormParameter parameter in parameters

We then loop through the all the parameters in the collection, where we can get  a list of the  following parameter properties

  1. Name
  2. Type
  3. Default value

Example of executing the method

SourceCode.Forms.Authoring.Form form = new SourceCode.Forms.Authoring.Form(frm.GetFormDefinition(forminfo.Name));

ArtifactParameters(form.parameters);

 

Controls

We had a look at getting the parameters so how about getting a list of all the controls

Like the parameters we pass in the ‘control’ object from the artifact and then we loop through all the controls in the collection.

The properties that we will be  using are the

  1. Name
  2. Type
  3. GUID
  4. Properties (properties of the control)

public List<SmartFormViewControls> ArtefactControls(SourceCode.Forms.Authoring.ControlCollection controls)
{
List<SmartFormViewControls> list = new List<SmartFormViewControls>();
foreach (SourceCode.Forms.Authoring.Control control in controls)
{
list.Add(new SmartFormViewControls {
name = control.Name,
type = control.Type,
guid = control.Guid,
properties = control.Properties

});

}
return list;
}

The control method is universal for both Smartforms and views.

This brings us nicely to the properties object

Properties

The below property method can be used to get the properties of a control such as it’s width, field etc.. But also more properties based from a view or Smartform and even a  rule.

public List<SmartFormViewProperties> ArtefactProperties(SourceCode.Forms.Authoring.PropertyCollection properties)
{
List<SmartFormViewProperties> list = new List<SmartFormViewProperties>();
foreach (SourceCode.Forms.Authoring.Property prop in properties)
{
list.Add(new SmartFormViewProperties
{
name = prop.Name,
value = prop.Value,

});

}
return list;
}

The method accepts the type ‘Property collection’ as an input parameter and then loops through the list of properties.

  1. Name is the name of the property  for example ‘Width’
  2. Value is value of the property for example ‘200px’

 

In the next part we will look at the ‘Events’ as there is a lot that goes into this.

 

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

 

 

 

2 thoughts on “Building a K2 Smartform spider part 3

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s