Table of Contents

External Functions

Purpose

External Functions are used for integrating with other systems, data sources and custom code. For example:


Note that for importing records into Digital-Clay, ClayIntegrator or Data Injection would be more suitable in most cases.

Overview

There are five types of External Functions:

Using External Functions

External Functions may be used in Digital-Clay in any of the following ways:


All External Functions may be configured to accept up to 20 parameters. Each of these parameters must then be mapped to values or fields when using them in any of the above scenarios.

Table

Purpose of the Table setting:

Note that this setting is disabled for Database Functions for now, since static parameters are not allowed with this type of function.

Parameters

There are two types of parameters:

Dynamic Parameters

These are defined in the External Function and then mapped to actual values, fields or functions when they are used in Automation actions etc.

This allows the same External Function to be used with multiple tables and dynamic values. For example, a generic ConvertCurrency function can be used in multiple tables wherever a currency needs to be converted if the Table is set to 'Any', and the relevant parameters are not static.

External Functions are currently limited to 20 dynamic parameters.

In Web Functions, it is also possible to send Document Templates as parameters. See below.

Static Parameters

These are defined in the External Function along with a static value or mapped field. These parameters will not appear in Automation actions and the parameters will be sent behind the scenes along with their values.

Unlimited static parameters may be added to an External Function.

Return Values

External Functions are further categorized according to the amount of parameters they return:


If the function returns multiple values for each parameter, only the first value is retrieved, unless it is for populating a drop-down.

Security

By default, External Functions may be run by anyone. To restrict the use of the function, remove some of the Roles in the External Function Roles listbox.

Note that when using External Functions in Automation actions, the function will only be called if the Automation Owner has the appropriate permissions.

Errors

If any errors or timeouts are encountered while attempting to call the External Function, they will be added to the Automation Log as usual. If the External Function is used in a custom function by a user, the user will receive the error in a message box.

To track errors and handle them automatically by Automation, you must use the Set Fields (External Function) action (not the Set Field action). This action allows you to set a field value when an error is thrown. Based on this 'error field' change event, you may configure Automation Event Handlers to send a message/email, or try to set the field values using alternative sources and functions.

Database Function

A Database Function must be created in the ClayCentral database (e.g. an SQL Server T-SQL stored procedure). Note that MDB databases do not support stored procedures since VBA functions cannot be called from external SQL queries.

Since the Database Function exists in the ClayCentral database, it is the only External Function that can be used in Digital-Clay Custom Functions for custom fields, filters, indicators and query columns.

A Database Function may return either a single parameter for use in queries and fields, or no parameters for use as a trigger/notification.

Sample function for counting the amount of spaces in a text value:

CREATE FUNCTION countSpaces (@var nvarchar(4000)) RETURNS INT AS 
BEGIN
 DECLARE @pos int; DECLARE @num int;
 SET @pos=1; SET @num=0;
 SET @pos=CHARINDEX(' ',@var,@pos);
 WHILE @pos>0
  BEGIN
   SET @num=@num+1;
   SET @pos=@pos+1;
   SET @pos=CHARINDEX(' ',@var,@pos);
  END;
  RETURN @num;
END


Note that to call this function, its internal function name must typically include its owner, e.g. The Internal Name should be “dbo.countSpaces”.

Also note that SQL Server functions cannot modify data or call stored procedures.

Database Stored Procedure

Identical to 'Database Function' above with the following differences:

The same sample function for counting the amount of spaces as above, only this time created as a stored procedure in SQL Server:

CREATE PROCEDURE countSpaces @var nvarchar(4000), @ret INT OUTPUT
AS
 DECLARE @pos int; DECLARE @num int;
 SET @pos=1; SET @num=0;
 SET @pos=CHARINDEX(' ',@var,@pos);
 WHILE @pos>0
  BEGIN
   SET @num=@num+1;
   SET @pos=@pos+1;
   SET @pos=CHARINDEX(' ',@var,@pos);
  END;
  SET  @ret=@num;


Web

Web Functions consist of:

Plain-Text Results

With this setting, all of the results are returned as a single parameter only. If the page is an HTML page, the complete page will be returned including HTML source code. This is typically useful only when the web page is designed to return values for applications rather than web browsers.

XML/XHTML Results

If the results of a URL are in XML or strict HTML format (i.e. all tags are closed and strict syntax is maintained). Then this format is preferred over HTML because it allows the program to retrieve results much more precisely.

To extract values from an XML document, Digital-Clay asks for an XPath statement per Return Parameter. Using XPath, you can specify exactly which node to retrieve, including its location in the document, its exact path and parents, attribute filters, the amount of nodes to skip, etc. For a quick primer on XPath, see http://www.w3schools.com/XPath/xpath_syntax.asp.

HTML Results

Since HTML results are typically unstructured and may contain dynamic content and structure, extraction is done by finding tokens before and after the text. To fine-tune and get exact results, tokens can be located in stages. To demonstrate this, let's use an example:

In this example, the following HTML source code is contained somewhere inside a larger HTML page:

Results for your query:<BR>
<div class='colheaderleft'>Name</div><div class='colheaderright'>Phone</div>
<div class='colvalueleft'>John Adams</div><div class='colvalueright'>888-654-3210</div>

…and we want to extract only the phone number. Here are some ways to approach this:


If you have done your best to find specific tokens but the end result may still contain unwanted HTML code, leave the “Remove HTML code” checkbox checked.

To be notified of a failure to find the tokens you entered, check the 'Treat token not found as error' setting. Otherwise it will only skip the parameter and not set its values in Digital-Clay.

Database

To be done…

SOAP

To be done…