How to receive Datalist from TIBCO Enterprise Runtime for R and extract its data

How to receive Datalist from TIBCO Enterprise Runtime for R and extract its data

book

Article ID: KB0084106

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition 5.4.0

Description

I have a R script which returns a list.
FraudDetectionList <- function(debitTime,debitAmount,averageMonthlyBalance)
{	
	debitTimeLength <- length(debitTime)
	debitAmountLength <- length(debitAmount)
	i<-2
	#Need to make 3 debits to trigger FraudDetection rule. Hence first condition is to see time length(Number of time history values) is greater than 2
	while(debitTimeLength>2)
	{
		while(i<debitTimeLength)
		{
			SumOfDebits <- 0
			k<-debitTimeLength-i
			for(z in debitTimeLength:k)
			{
				SumOfDebits <- SumOfDebits+debitAmount[[z]]
			}
			if((debitTime[[debitTimeLength]]!=0) && (debitTime[[debitTimeLength]]-debitTime[[debitTimeLength-i]]<=FraudCriteria.interval) && (SumOfDebits>(FraudCriteria.debitsPercent*averageMonthlyBalance)))
			{
				result=list(TRUE,"FraudDetected")
				return(result)
			}
			else
			{
				i <- i+1
			}
		}
			debitTimeLength <- debitTimeLength-1
			i<-2
	}
		result=list(FALSE,"OK")
		return(result)
}
How to receive Datalist from TIBCO Enterprise Runtime for R and extract its data in a TIBCO BusinessEvents Rule/Rulefunction?

Issue/Introduction

How to receive Datalist from TIBCO Enterprise Runtime for R and extract its data.

Environment

All

Resolution

Complex Data structure DataList TERR type is mapped to Object in TIBCO BusinessEvents Rule/Rulefunction. Use Object for the DataList(com.tibco.terr.TerrList) returned from TERR, and then use the Analytics.DataList.getElement catalog function to extract the list(Object[]).

See the code example below to extract elements returned from TERR in a BE Rule/Rulefunction: 
Object[] TerrResult = Analytics.Engine.invokeTERRFunction("TerrEngine","FraudDetectionList",debitTime,debitAmount,averageMonthlyBalance);

Object TerrResultList = TerrResult[0];

Object[] firstElement = Analytics.DataList.getElement(TerrResultListObject, 0);
int fraudFlag = Number.valueOfString(firstElement[0]);

Object[] secondElement = Analytics.DataList.getElement(TerrResultListObject, 1);
String fraudMessage = secondElement[0];