cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating reusable function libraries on the Axeda Platform

ckaminski
13-Aquamarine

Creating reusable function libraries on the Axeda Platform

One recurring question that comes up after a customer has been using the scripting capabilities of the Axeda Platform for some time is how to create function libraries that are reusable, in order to reduce the amount of copy and pasting (and testing) that is done to create new functionality.  Below I demonstrate a mechanism for how to accomplish this.  Some things that are typically included in such a library are:

  • Customized ExtendedObject access methods (CRUD) - ExtendedObjects must be created before they can be used, so this can be encapsulated per customer requirements
  • DataItem manipulation
  • Gathering lists of Assets based on criteria
  • Accessing the ExternalCredentialsBridge

For those unfamiliar with Custom Objects I suggest some resources at the end of this document to get started.  The first thing we want to do is create a script that is going to be our "Library of Functions":

FunctionLibrary.groovy:

class GroovyChild {

    String hello() {

        return "Hello"

    }

    String world() {

        return "World"

    }

}

return new GroovyChild()

This can the be subsequently called like this:

FunctionCaller.groovy:

import static com.axeda.sdk.v2.dsl.Bridges.*

import com.axeda.services.v2.CustomObjectCriteria

import com.axeda.services.v2.CustomObjectType

import com.axeda.services.v2.CustomObject

CustomObjectCriteria cOC1 = new CustomObjectCriteria()

cOC1.setName 'FunctionLibrary'

def co = customObjectBridge.findOne cOC1

result = customObjectBridge.execute(co.label )

return ['Content-Type': 'application/text', 'Content': result.hello() + ' ' + result.world() ]

A developer would be wise to add in null checking on some of the function returns and do some error reporting if it cannot find and execute the FunctionLibrary.  This is only means a a means to start the users on the path of building their own reusable content libraries.

Regard

-Chris Kaminski

PTC/Axeda Customer Support

References:

0 REPLIES 0
Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.