Configuring Unbound Functions
The framework supports configuring unbound functions in a domain. In the OData protocol, an unbound function is considered to be an operation that does not change the state of a service. The framework treats an unbound function as a read-only operation available in a domain. After the unbound function is configured, it is invoked by a GET request to the URL:
<Domain Root>/<Unbound Function Name>(<param1>=<value1>, <param2>=<value2>)
|
When you implement custom functions ensure that the function does not create, update, or delete data. The function should only read and retrieve data. Functions that write or update data can cause unexpected data creation or modification in Windchill.
|
To configure an unbound function, perform the following steps:
1. Specify the properties of the function: name, input parameters, and return type.
2. Define the implementation logic for the function.
The properties of an unbound function are specified in the import.json file of the domain. In the file, under functions, specify the following properties:
• name—Name of the unbound function. The function is invoked from the URL with this name.
• importName—Name of the import operation. This is the name that will be in the URI when the unbound function is invoked. For more details about function imports, see the
OData specifications.
• description—Description of the function. The value will be displayed as an annotation (Core.Description) in the EDM.
• includeInServiceDocument—This is applicable for unbound functions. Defines if the function can be requested as a service in the container. The default value is set to false.
• parameters—A collection of parameters to be passed to the function. You can specify multiple parameters separated by commas. Specify the following parameters for a function:
◦ name—Name of the parameter in camel case.
◦ type—Type of the parameter. The parameter can be a primitive, complex, or an entity type. If the parameter is an entity type, the value is specified in the URL to the entity.
◦ isNullable—Specifies if a property can be set as null. The default value is set to false.
◦ isCollection—Specifies if the property represents a collection. The parameter takes one (false) or multiple (true) values. The default value is set to false.
• returnType—Information about what the function returns. Specify the following properties for the return types:
◦ type—Type of object that is returned. The return type can be a primitive, complex, or an entity type.
◦ isNullable—Specifies if a property can be set as null. The default value is set to false.
◦ isCollection—Specifies if the property represents a collection of objects or entities. The default value is set to false.
For example, consider a configuration file import.json for an unbound function GetEndItems. The function returns a collection of Part entities, and takes no input parameters:
{
"imports:[
{“name”:"PTC", “version”:"1"},
{“name”:"DataAdmin", “version”:"1"}
],
"functions":[{
"name": "GetEndItems",
"description": "Gets a list of end items parts",
"parameters": [],
"returnType": {
"type": "Part",
"isCollection": true
}
}]
"actions":[]
}
An unbound function is implemented in the import.js file. The function is implemented as below:
• The function name starts with function_, followed by the name of the function that is defined in the import.json file.
• The function takes two input parameters:
◦ data—The parameter is of type FunctionProcessorData, which is a data structure, that contains information about the processing logic of the framework. This information can be used while implementing the function.
◦ params—The parameter is of type Map<String, Parameter> and it contains the hashmap of input parameter names and values passed by the client to the function. The name of the input parameter is the key in the map and the parameter value passed by the client is the value for the key.