Building a K2 Smartform spider part 4

Rules

In part 3, we looked at how to get additional information from Smartform such as parameters and controls. In part 4 we will now look at how to be able to get the rules from the forms and views.

This is probably most complex part of the API as it involves a number of different methods to get the  necessary information.

To access the rules  of the artifact we need to use the following code as we did in part 3 this will give us access to the Events object.

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’));

So lets take a look and see what we can from the events object

Events

Majority of rules in Smartforms and views start with an event.  An event is when something happens such as a ‘click of a button’.

public List<SmartFormViewEvents> ArtefactEvents(SourceCode.Forms.Authoring.Eventing.EventCollection events)
{
List<SmartFormViewEvents> list = new List<SmartFormViewEvents>();
foreach (SourceCode.Forms.Authoring.Eventing.Event ev in events)
{

if (ev.SourceType == SourceCode.Forms.Authoring.Eventing.EventSourceType.Rule)
{
list.Add(new SmartFormViewEvents
{
name = ev.Name,
type = ev.EventType.ToString(),
handlers = ev.Handlers,
properties = ev.Properties

});

}
}

return list;
}

The above method gives a list of all the events on the artifact and access to more additional objects

First thing we do is we loop through the event collection and we check to see if the event type is the ‘Rule’ type.

if (ev.SourceType == SourceCode.Forms.Authoring.Eventing.EventSourceType.Rule)

The objects we want to have access to are the following

  1. Name
  2. Type
  3. Handlers
  4. Properties

The important object from this is the Handlers, as this will give us access to the Conditions and Actions of the rule.

Handlers

The handler object is where we can drill down into the rule and access the conditions of the rule and also the actions of the rule.

public List<SmartFromViewHandlers> ArtefactHandlers(SourceCode.Forms.Authoring.Eventing.HandlerCollection handlers)
{
List<SmartFromViewHandlers> list = new List<SmartFromViewHandlers>();
foreach (SourceCode.Forms.Authoring.Eventing.Handler handle in handlers)
{
list.Add(new SmartFromViewHandlers
{
Actions = handle.Actions,
Conditions = handle.Conditions,
Name = handle.HandlerType.ToString()
});

}

return list;

}

The methods starts by passing in the handler object from the previous method, now the method can loop through the all the handlers for that particular event

foreach (SourceCode.Forms.Authoring.Eventing.Handler handle in handlers)

On each loop, we can then access the following objects

  1. Name
  2. Conditions
  3. Actions

Conditions

Conditions check to see if something is equal to true, for example ‘all the required fields are entered’.

public List<SmartFormViewConditions> ArtefactConditions(SourceCode.Forms.Authoring.Eventing.ConditionCollection conditions)
{
List<SmartFormViewConditions> list = new List<SmartFormViewConditions>();
foreach (SourceCode.Forms.Authoring.Eventing.Condition condition in conditions)
{

list.Add(new SmartFormViewConditions
{
Property = condition.Properties
});
}

return list;
}

 

Actions

So we can access the event, the conditions and now lets look how we can access the actions of a rule.

public List<SmartFormViewActions> ArtefactActionss(SourceCode.Forms.Authoring.Eventing.ActionCollection actions)
{
List<SmartFormViewActions> list = new List<SmartFormViewActions>();

foreach (SourceCode.Forms.Authoring.Eventing.Action action in actions)
{
list.Add(new SmartFormViewActions
{
properties = action.Properties,
parameters = action.Parameters,
results = action.Results,
validation = action.Validation,
viewguid = action.ViewGuid,
method = action.Method,
formguid = action.FormGuid,
executiontype = action.ExecutionType.ToString(),
controlguid = action.ControlGuid,
actiontype = action.ActionType.ToString()
});
}
return list;
}

Using the above method, we can get the complete information of the action.  The action opens up some additional objects that we can explore to get more detailed information about the action.

Below are some examples of the more useful ones

Action Parameters

public List<SmartFormViewActionParameters> SmartFormViewActionParameters(SourceCode.Forms.Authoring.Eventing.MappingCollection parameters)
{
List<SmartFormViewActionParameters> list = new List<SmartFormViewActionParameters>();
foreach (SourceCode.Forms.Authoring.Eventing.Mapping map in parameters)
{

list.Add(new SmartFormViewActionParameters
{

validation = map.Validation,
targettype = map.TargetType.ToString(),
targetpath = map.TargetPath,
targetid = map.TargetID,
sourcevalue = map.SourceValue,
sourcetype = map.SourceType.ToString(),
sourcepath = map.SourcePath,
sourceid = map.SourceID

});
}

return list;
}

Action Results

public List<SmartFormViewActionParameters> SmartFormViewActionResults(SourceCode.Forms.Authoring.Eventing.MappingCollection Results)
{
List<SmartFormViewActionParameters> list = new List<SmartFormViewActionParameters>();
foreach (SourceCode.Forms.Authoring.Eventing.Mapping result in Results)
{

list.Add(new SmartFormViewActionParameters
{

validation = result.Validation,
targettype = result.TargetType.ToString(),
targetpath = result.TargetPath,
targetid = result.TargetID,
sourcevalue = result.SourceValue,
sourcetype = result.SourceType.ToString(),
sourcepath = result.SourcePath,
sourceid = result.SourceID

});
}
return list;
}

Action Validation

public List<SmartFormViewActionValidation> SmartFormViewActionValidations(SourceCode.Forms.Authoring.ValidationResult validations)
{

List<SmartFormViewActionValidation> list = new List<SmartFormViewActionValidation>();

SourceCode.Forms.Authoring.ValidationResult validation = validations;

list.Add(new SmartFormViewActionValidation
{
messages = validation.Messages,
status = validation.Status.ToString()
});
return list;
}

Action Messages

public List<SmartFormViewActionValidationMessage> SmartFormViewActionValidationMessages(ValidationMessageCollection messages)
{
List<SmartFormViewActionValidationMessage> list = new List<SmartFormViewActionValidationMessage>();
foreach (ValidationMessage message in messages)
{
list.Add(new SmartFormViewActionValidationMessage
{
message = message.Message
});
}
return list;
}

 

In the next part, we will take the methods we have explored in parts 1 to 4 and put it altogether to build the form spider.

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

 

One thought on “Building a K2 Smartform spider part 4

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