Pass connection


How can I pass connection from admin UI to server using rest.
P.S: When using rest I lost connection in server method.
function testTwo(ctx) {
var cs = Ext.decode(App.customSettings);
var UBConnection = require(‘UBConnection’);

conn = new UBConnection({host: cs.atuAPIRemoteHost, port: cs.atuAPIRemotePort, path: cs.atuAPIRemotePath, receiveTimeout: receiveTimeout, keepAlive: true});
conn.onRequestAuthParams = function(){ return {authSchema: cs.atuAPIRemoteAuthSchema, login: cs.atuAPIRemoteLogin, password: cs.atuAPIRemotePassword}};
var rootObjects = conn.get('rest/neo_PlanChangeItem/test');


try to use function helper but catch this error: POST ubql ERROR=500 ({ “ClassName”:“ESMException”, “Address”:"005E4F97 ", “ErrorNum”: 0, “Stack”: “Module._resolveFilename@module.js:478:15\nModule._load@module.js:426:18\nModule.prototype.require@module.js:506:10\nrequire@internal/module.js:20:14\ntestTwo@D:\My App\Kostyshyn\Neocom\06-Source\03-Portal\models\NEO\neo_PlanChangeItem.js:62:24\n”, “FileName”: “module.js”, “Line”: 478, “Message”: “Cannot find module ‘UBConnection’” })
Аlso try to require file in diferent ways.
In the extreme case I can pass data in post request from admin UI but this data stored in 6 tables, so passing data like
DB-> server ->admin UI -> server a little bit bad


UB version 4.1.0-beta6


In case you need to connect from one UB server to another, use a @unitybase/base module (new in UB4):

const UBConnection = require('@unitybase/base/UBConnection')
// your code

Documentation is a little bit outdated.

And try to avoid using Ext on the server side - Ext is deprecated in UB4.

Instead of

var cs = Ext.decode(App.customSettings)

Better to write

let cs = JSON.parse(App.customSettings)

Or even more better

let cs = App.serverConfig.application.customSettings

In UB4 server-side property App.serverConfig is a parsed content of ubConfig.json