Default way to access other Server-Side Business Objects
Prerequisites
To access other Server-Side Business Objects you have to add them in Business-Object Settings. Else the requested Server-Side Business-Object is not found on execution and dependency can not be handled on transporting.
Access other business objects
You can call any other business objects in your current one in a similar way than calling a connector, using the following syntax:
Simplifier.BusinessObject.<BOName>.<MethodName>(payload?: string|object, parametrized?: boolean = true): object Simplifier.CurrentBusinessObject.<MethodName>(payload?: string|object, parametrized?: boolean = true): object
Examples:
var otherMethodResult = Simplifier.BusinessObject.OtherBO.someMethod({"foo": "bar"}); var unparamtetrizedResult = Simplifier.BusinessObject.OtherBO.someMethod("{\"foo\": \"baz\"}", false); var sameBoResult = Simplifier.CurrentBusinessObject.someMethodOnSameBO({"baz": "baz"}); var noArgsResult = Simplifier.CurrentBusinessObject.methodWithoutArgs();
Call Server Side Business Objects dynamically
What does dynamic calling mean?
Imaging Simplifier Integrations act as a middleware between a lot of different front-end applications like online shops and every single shop requires a different backend system (via connectors) or different business logic.
So let’s visualize this:
Ways of dynamic Calls
If you want to create a business object dynamically, you have three options
- Use Variables for Business Objects Names and Calls instead fixed names
- Use our dynamic Call Function
- Use a Simplifier REST Connector to execute Business Objects via our Client API
This article covers the first two options, the third option is not recommended due to performance reasons and therefore not addressed in this documentation.
Option 1: Calling Business Objects using Variables
In this scenario, we call the Business Objects using Variables for the Name and Call
Preparation
All Business Objects called in this way have to be referenced before in the Caller Business Object. So, edit the Source Business Object from which you will call the other Business Objects and add them to the References:
Integration
The Dynamic Call of the Business Object has the following syntax
Simplifier.BusinessObject[sNameOfObject][sNameOfFunction](oPayload).return;
Example
Lets build a litte code for the Shop Scenario explained in the Introduction. We cover 2 Shops , one with ID 232 and one with ID 453 – instead of calling a Business Object like
output.stock = Simplifier.BusinessObject.SAPERP.readStockStatusfromWM(oPayload).stock;
we use this dynamic calling:
output.stock = Simplifier.BusinessObject[sBoName][sBoFunction](oPayload).stock;
Here the complete example: /** * This function acts as are generic api that is capable to read stock information from different backends depending on ShopID **/ try { let sBoName, sBoFunction; let oPayload = input; // check which shop are the requester switch (input.ShopID) { case 232: sBoName = "SAPERP"; sBoFunction = "readStockStatusfromWM"; break; case 453: sBoName = "Infor"; sBoFunction = "readStockfromIMHub"; break; default: // in case of no shop id , raise an error throw "Shop ID is not valid"; } // run Business Object dynamically output.stock = Simplifier.BusinessObject[sBoName][sBoFunction](oPayload).stock; } catch (e) { throw e.message; }
Option 2: Calling Business Objects using dynamicBusinessObjectCall
In this scenario, we call the Business Objects using the method dynamicBusinessObjectCall.
Preparation
To be able to use the new Method dynamicBusinessObjectCall you have to activate the Setting “Allow dynamically calling server side Business Objects” in the Server Settings.
Integration
The Dynamic Call of the Business Object has the following syntax
Simplifier.dynamicBusinessObjectCall("NameofConnector", "MethodName", $payload).return;
Example
Lets build a litte code for the Shop Scenario explained in the Introduction. We cover 2 Shops , one with ID 232 and one with ID 453 – instead of calling a Business Object like
output.stock = Simplifier.BusinessObject.SAPERP.readStockStatusfromWM($payload).stock;
we use this dynamic calling:
output.stock = Simplifier.dynamicBusinessObjectCall("SAPERP", "readStockStatusfromWM", $payload).stock;
Here the complete example:
/** * This function acts as are generic api that is capable to read stock information from different backends depending on ShopID **/ try { let sBoName, sBoFunction; let oPayload = input; // check which shop are the requester switch (input.ShopID) { case 232: sBoName= "SAPERP"; sBoFunction = "readStockStatusfromWM"; break; case 453: sBoName = "Infor"; sBoFunction = "readStockfromIMHub"; break; default: // in case of no shop id , raise an error throw "Shop ID is not valid"; } // run Business Object dynamically output.stock = Simplifier.dynamicBusinessObjectCall(sBoName,sBoFunction,oPayload).stock; } catch (e) { throw e.message; }