前页 | 后页 |
Example Script
This JavaScript script details how to send a simple request to a Custom Service plugin:
!INC Local Scripts.EAConstants-JavaScript
/*
* Script Name: Custom Service Example
* Author: Sparx Systems
* Purpose: Demonstrate the use of the SBPI automation interface for Custom Service plugins
* Date: 2022-02-28
*/
// Sends a simple request to the plugin with some parameters.
function SimpleRequest()
{
// Show the script output window
Repository.EnsureOutputVisible( "Script" );
Session.Output("JavaScript Custom Plugin EXAMPLE");
Session.Output("=======================================");
// Send data with the request by adding parameters using InsertSBPIParameter.
var packedParameters = '';
// Optional data to send with extra parameters
packedParameters = Repository.InsertSBPIParameter(packedParameters, 'myNumber', 25);
packedParameters = Repository.InsertSBPIParameter(packedParameters, 'myFloat', 123.456);
packedParameters = Repository.InsertSBPIParameter(packedParameters, 'myString', 'Hello World');
Session.Output("Sending simple request to plugin to 'DoSomething' method");
var response = SBPIRequest('csvc', 'DoSomething', packedParameters);
}
// Helper function to send a request to the Custom plugin and check for errors.
function SBPIRequest(prefix, method, packedParameters)
{
// Specify the prefix of the plugin. This is configured in the Pro Cloud Config Client.
var response = Repository.CallSBPI(prefix, method, packedParameters);
if (response == '')
{
Session.Output('Error from plugin: ' + Repository.GetLastError());
}
else
{
Session.Output('Success: ' + response);
}
return response;
}
function main()
{
// Sends a simple request to the plugin with some parameters.
SimpleRequest();
}
main();