function

Sends a function and its parameters to the server to run synchronously, asynchronously, or at a scheduled time.

Parameters

function
Required. The function to run. If the user does not supply this parameter, the server returns an appropriate error message. Follow with a question mark (?) and the arguments. (See the Example for more information.)
package
The name of the library or package that contains function.
arg
The function's arguments, separated by an ampersand (&). (See the Example for more information.)
async
A logical value. true if the function is to be run asynchronously; otherwise false.
at
The time, in milliseconds, since epoch to schedule the job at a future date.

Return value

If run asynchronously, the resulting SPXML string contains only the jobId and job status; if run synchronously, the resulting SPXML string contains the results of the evaluation. See Remarks for more information.

Remarks

Note: Each function call is a separate evaluation, and the function you call must exist on the server. You can deploy your own functions in libraries or packages, and then include the package in the path. For example:
http://servername:8080/SplusServer/api/v8/function/libraryname/functionname

Each evaluation is known as a "job." Jobs can be run synchronously or asychronously. A synchronous job retains control of the browser and waits for the returned SPXML; an asychronous job sends the request to the server and returns control to the browser, allowing you to continue working, and allowing the job to run at a later time.

The jobId is a property of the SPXML results string and appears as follows:

<SplusDataResult hasReturnValue="true" hasTextOutput="true" 
hasError="false" hasWarnings="false" created="Weds Mar 6 12:40:36 PDT 2019" 
jobId="111" status="2">

When you send an asynchronous evaluation request, the SPXML results return immediately, but they contain only the jobId and job status. You can capture and use the jobId to find your results in the results directory at a later time.

Note: If you schedule a request, and you specify an invalid time (for example, in the past), the request is run synchronously, on the first available engine.

Example

Note: In the example, the URL path includes rnorm, a function that exists in a library that is loaded when the engine starts. If you want to call a function that is in a package not loaded on engine startup, talk to you server administrator about adding it to the init script.
http://servername:8080/SplusServer/api/v8/function/rnorm?n=5&mean=30
Note: The function API is designed specifically for calling user-created functions through Spotfire Statistics Services. It does not handle unnamed arguments, and all parameters are passed to the function as strings. The user functions should be written with these constraints in mind and the functions should coerce the parameters to desired data types as necessary. To execute arbitrary expressions, use the eval function in the Expression Service API. For more information about writing a function to be called on the server, see the TIBCO Spotfire Statistics Services User's Guide.
Related reference