The new JavaScript client API’s on AppWorks client can be used for developing custom pages/navigation as per the need of the application. Till now any custom logic written outside and embedded in the AppWorks client (as XForm or HTML page in a Webcontent panel) doesn’t have a tighter integration which requires a hard refresh of client to see the updates. Now with the new API’s, custom pages can communicate with AppWorks client to read/update an entity instance details and also allows you to perform navigation and actions from outside the AppWorks client.
These client API provides easy access to Entity data available in AppWorks client and navigation across multiple items/layouts through API's
- Navigation across different layouts
- Read data or relation of an Entity instance
- Update the data of an Entity instance
- Save the data of an Entity instance
- Perform Action on an Entity instance
Note: The JavaScript APIs use the Promise syntax for returning values. For more information see Promise syntax and its usage.
Navigation across different layouts
The API navigate()
is used to navigate to a specific Item instance or a Home layout.
publicAPIProvider.navigate(ID,
{"layoutId": 'layoutID', "clearBreadcrumb": true, "breadcrumbName":'newName'})
Parameters description
+------------------+-----------------------------------------------------------------+
| Name | Description |
+------------------+-----------------------------------------------------------------+
| ID | Mandatory. |
| | ID of the Homepage layout or the Item to navigate. |
+------------------+-----------------------------------------------------------------+
| layoutId | Optional. |
| | Layout ID of the item to navigate when its an Item to navigate. |
+------------------+-----------------------------------------------------------------+
| clearBreadcrumb | Optional. |
| | Boolean. Clears the existing breadcrumb when 'true'. |
+------------------+-----------------------------------------------------------------+
| breadcrumbName | Optional. |
| | Name of the breadcrumb to populate when navigated to a new page.|
+------------------+-----------------------------------------------------------------+
Return Value
The API returns a promise and upon fulfilling the promise, values are returned. Boolean, 'true' when the navigation is successful.
Example:
When you load your custom html in a Webcontent panel, you can use the API as below.
window.parent.publicAPIProvider.navigate(itemID,{'clearBreadcrumb':false,'breadcrumbName':'Seat selection', 'layoutId':'<ID of layout>'});
Read data or relation of an Entity instance
The API getItemData()
is used to obtain an item's details such as properties and relationships for the itemID.
You can also use this API to get the latest data to client data when the data is updated in the background.
publicAPIProvider.getItemData(itemID, {"refresh":true,"relationName":"Name"});
Parameters description
+------------------+------------------------------------------------------------------------+
| Name | Description |
+------------------+------------------------------------------------------------------------+
| itemID | Mandatory. |
| | Item ID of the Entity instance. |
+------------------+------------------------------------------------------------------------+
| refresh | Optional. |
| | Boolean. When set to 'true', details are always |
| | retrieved from the server. |
+------------------+------------------------------------------------------------------------+
| relationName | Optional. |
| | Name of the required relationship. |
+------------------+------------------------------------------------------------------------+
Return Value
The API returns a promise and upon fulfilling the promise, values are returned. Item object when a valid item is available.
Example:
When you load your custom html in a Webcontent panel, you can use the API as below.
window.parent.publicAPIProvider.getItemData(itemID).then((itemData) => {
// Your custom logic and itemData has the details
});
Update the data of an Entity instance
The API updateData()
is used to update the data related to particular instance.
publicAPIProvider.updateData(itemID, propertyName, propertyValue)
Parameters description
+------------------+------------------------------------------------------------------------+
| Name | Description |
+------------------+------------------------------------------------------------------------+
| itemID | Mandatory. |
| | Item ID of the Entity instance. |
+------------------+------------------------------------------------------------------------+
| propertyName | Mandatory. |
| | Name of the property as defined in design. |
+------------------+------------------------------------------------------------------------+
| propertyValue | Mandatory. |
| | Value of the property . |
+------------------+------------------------------------------------------------------------+
Return Value
The API returns a promise and upon fulfilling the promise values are returned. Boolean, 'true' when the update is successful.
Example:
When you load your custom html in a Webcontent panel, you can use the API as below.
window.parent.publicAPIProvider.updateData(itemID, '<property name>', '<property value>');
Save the data of an Entity instance
The API saveAllItems()
is used to save the data of all items.
publicAPIProvider.saveAllItems()
Return Value
The API returns a promise and upon fulfilling the promise no values are returned.
Example:
When you load your custom html in a Webcontent panel, you can use the API as below.
window.parent.publicAPIProvider.saveAllItems();
Perform Action on an Entity instance
The API performAction()
is used to trigger action on an Entity instance.
publicAPIProvider.performAction(itemID, actionName)
Parameters description
+------------------+------------------------------------------------------------------------+
| Name | Description |
+------------------+------------------------------------------------------------------------+
| itemID | Mandatory. |
| | Item ID of the Entity instance. |
+------------------+------------------------------------------------------------------------+
| actionName | Mandatory. |
| | Name of the action to be performed. |
+------------------+------------------------------------------------------------------------+
Return Value
The API returns a promise and upon fulfilling the promise values are returned. Boolean, 'true' when the action is successful.
Example:
When you load your custom html in a Webcontent panel, you can use the API as below.
window.parent.publicAPIProvider.performAction(itemID, '<action name>');
Happy development using of new client JavaScript API' for building better integrations in your Application 😊