<< 目次を表示 >> ページ位置: プロジェクトの作成と管理 > Proクラウドサーバ > 有料ライセンスで利用できる機能 > 外部ツールとの連携 > 独自のSBPIサービス > サンプルスクリプト |
独自のSBPIサービスに接続する簡単なJavaScriptのサンプルです。
!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();