You can call a business object behavior from a user interface method by making httpClient call. To call the behavior you need to first grab the behavior url and then define parameters, if any.
Set the URL
Go to the business object behavior page (see Business Object Behaviors for details), and open the settings dialog by clicking :
Note the "Path" field from the settings dialog. Create a user interface method and set the url variable equal to the value of the "Path" field (see User Interface Methods for creating a method).
For a class behavior, the url would be something like this:
let url = 'Orders/myCart';
For an instance behavior, the path would require object's id as well. You can set it like this:
let url = `Orders/${this.order.id}/myCart`;
Define Parameters
GET Api
Any inputs to a GET behavior are passed as Query Parameters.They appear at the end of the request URL after a question mark (?), with different name=value pairs separated by ampersands (&). When passing an object as an input value, you need to encode it:
let startDate = encodeURIComponent(this.startDate);
let endDate = encodeURIComponent(this.endDate);
let url = `Orders/findByStatus?status=Complete&startDate=${startDate}&endDate=${endDate}`;
Setting the Location of your behavior parameters as Query String is the default. However, you can set them as URL Path or Header too. Check the OpenAPI guide on how to pass them from a client.
Other APIs
Any inputs to a POST, PUT, PATCH or DELETE behaviors are passed as an object. If the behavior takes inputs "name" and "email", you can set the body in your method like this:
let body = {
name: this.personName,
email: this.personEmail,
};
Call the Behavior
Now you are ready to call the behavior in your method:
//calling a GET behavior
let orders = await this.httpClient.get(url).toPromise();
//calling a POST behavior
let person = await this.httpClient.post(url, body).toPromise();