Extension.Api.ErpCommunication reference
Extension in Sana has access to ERP communication functionality via Api.ErpCommunication
property.
This property serves as an entry point to make ERP calls, format requests and parse responses.
ERP methods names which are called from add-ons must have 'Addon_' prefix. This prefix is added automatically by Sana, add-ons should
specify method names without the prefix when call ExecuteAddonOperationAsync
method.
Properties
IsOfflineMode
Indicates if Sana is in offline mode. Offline mode in Sana means that ERP connection is unavailable and add-ons shouldn't make calls to ERP system.
ValueFormatter
Gets the instance of the ValueFormatter
type. Provides functionality to format values for ERP request.
See Extension.Api.ErpCommunication.ValueFormatter reference.
var formattedValueForErp = Api.ErpCommunication.ValueFormatter.FormatBool(true);
ValueParser
Gets the instance of the ValueParser
type. Provides functionality to parse values from ERP response.
See Extension.Api.ErpCommunication.ValueParser reference.
var dateFromErp = Api.ErpCommunication.ValueParser.ParseDate(dateString);
Methods
ExecuteAddonOperationAsync
Executes the specified add-on operation. It has following signature:
Task<XElement> ExecuteAddonOperationAsync(string operationName, IReadOnlyList<XElement> parameters);
First argument operationName
specifies operation name to call.
It cannot be used for standard ERP operations of Sana. All add-on operation names must have 'Addon_' prefix in the ERP. This prefix is automatically added by the method.
For example, extension developer should specify 'GetCustomData' operation name to call ERP method 'Addon_GetCustomData'.
Second argument parameters
defines the list of parameters which will be sent to the ERP.
Sana adds WebsiteId
parameter automatically for every request.
The method returns XElement
which contains Result
node from ERP response.
ERP connection should not be used in offline mode. To avoid this situation you can check IsOfflineMode
property before calling
ExecuteAddonOperationAsync
method.
The method throws Sana.Extensions.Connection.ErpException
in case of connection error.
Usage example
if (Api.ErpCommunication.IsOfflineMode)
return;
var parameters = new List<XElement>()
{
new XElement("Parameter1", "param1"),
new XElement("Parameter2", "param2")
};
try
{
var result = await Api.ErpCommunication.ExecuteAddonOperationAsync("GetCustomData", parameters);
var data = result.Element("Data").Value;
}
catch (Sana.Extensions.Connection.ErpException)
{
// handle connection error here
}
XML request example
<?xml version="1.0"?>
<Request>
<Operation>Addon_GetCustomData</Operation>
<Params>
<Parameter1>param1</Parameter1>
<Parameter2>param2</Parameter2>
<WebsiteId>SanaStore</WebsiteId>
</Params>
</Request>
XML response example
<?xml version="1.0"?>
<Response>
<Result>
<Data>data</Data>
</Result>
</Response>
ExecuteAddonOperationAsync
method will return Response
XML node from the ERP response.
This node can contain data in any format. It is reposibility of extension developers to parse it correclty.