Datapolis Process System SDK

Search:

Contents
:
IndexBookmarkPrint
Home > Functions > Function Code

Function Code

 

 

Below you will find basic information about coding functions in Datapolis Process System.

 

Requirements


For coding function you need to have in your project references to:

  • Datapolis.WorkBox.Common - for useful methods (i.e. logger)
  • Datapolis.WorkBox.Functions - for interface you need to implement while creating function

to create class that implements IWBFunctionBase interface. This interface is available in Datapolis.WorkBox.Functions assembly which you need to reference in your project. This assembly is installed with Datapolis Process System and is uploaded to GAC. This interface requires to implement Execute() method.

 

Implementation


Function which you create should implement interface Datapolis.WorkBox.Functions.IWBFunctionBase

 

public class WBHour : IWBFunctionBase

 

The main entry point where a function can implement its business logic is overriding the method: Execute():

 

public object Execute(WBFunctionExecutionContext functionExecutionContext)
{
    //Some code
    return "Some value";
}

 

Function Properties


Function can have properties that can be set by workflow. They should be declared as simple types (string, int, double, bool, DateTime).

Example property definition:

public DateTime? Value { get; set; }

Function Context


As a parameter in Execute method is provided WBFunctionExecutionContext. It contains data about actual context:

  • CorrelationId - this is guid representing request context. This guid is generated and stays same in below contexts:
    • Action Launch Form - for every lookup that is rendered on form
    • Workflow Initiation Form - similar as above
    • Activity lookup resolving - for every lookup that is provided as parameter to activity CorrelationId will stay same.

Example 1: If you open Action Launch Form on which you have used your function two times (e.g. in footer)​, both runs of Execute method will gather the same CorrelationId

Example 2: If you open Action Launch Form two times (e.g. by refreshing window in browser) and you have already used your function on this form then each request to your function will get different CorrelationId

  • Locale and RegionalSettings - returns properties of current Web Site.

Please note that there is no SPWeb object where workflow runs in WBFunctionExecutionContext and accessing it by SPContext.Current.Web is highly not recommended due to possibility of running your function in SharePoint Timer Service where SPContext is null. Below you will find example of Execute method where Locale is used.

 

public object Execute(WBFunctionExecutionContext functionExecutionContext)
{
    logger.Verbose("Function start");
    if (string.IsNullOrEmpty(this.Value))
    {
        logger.Medium("Value = [NULL] or Empty");
        logger.Verbose("Output: [NULL]");
        logger.Verbose("Function end");
        return null;
    }
    logger.Verbose("Value = " + Value.ToString());
 
    object result = WBVariableTypeHelper.ParseMathExpression(this.Value, functionExecutionContext.Locale);
    if (result == null) logger.Monitorable("Output: [NULL]");
    else
    {
        logger.Verbose("Output: " + result.ToString());
        result = string.Format(functionExecutionContext.Locale, "{0}", result);
 
    }
    logger.Verbose("Function end");
    return result;
}