With the OData functionality, you can easily display the related attachments of objects (such as displaying the attachments of customer opportunities on the customer, displaying the attachments of Level2 accounts on Level1 accounts, and showing the attachments of sub-tickets on the main tickets). In this way, you do not need to copy and add attachments to another business object, and you do not need to think about newly added or deleted attachments!
In this blog, we will explain step by step how you can view attachments related to objects with the OData function. On the customer’s business object, follow these steps to see the attachments of the customer’s opportunities.
1. Creating custom business object, necessary fields, and actions (clear, update attachments)
Choose ‘AccountID’ as the key, since we will make a new Embedded Component (EC) for the account.
For attachments fields (attachment name, process type, OData link, category code), we created a node attachments (ID, UUID, Name fields for Opportunities ID, UUID, Name). Also, add the clear and update actions so that attachments are updated every time the EC is opened.
2. Filling ClearAttachments and UpdateAttachments actions to update related attachments
Firstly, you need to clear attachments to update current attachments in the custom business objects.
In the UpdateAttachments, firstly find the customer’s opportunities with the help of a query. Then for each opportunity, return the attachments. For each attachment, fill the necessary fields of your custom objects with the opportunities attachment’s field. The important point is that if the attachment category code equals “3” (WebUri), you can take the link directly. But if the attachment category code equals “2” (LocalFile), you need to arrange the OData link. You can check the OData link from the “OData Service Explorer” under the “Administrator”.
Once you have filled in all the fields, create a record of your Attachment node and everything is done in action.
Now, you can create an embedded component for the customer business object.
3. Creating embedded components for related attachments tab
Firstly, arrange the required binding in the embedded component’s data model.
Then put the required fields in the designer. For OpenAttachments, make the “AttachName” as a link and put its onClick to new event handler using the name “OpenLink”.
Next, add new inport in the controller and fill in the required inport data in the data model. Name the new event handler “Init”.
After that, you need to set up your event handlers (Init and OpenLink).
When setting up ‘’Init’’, you first need to read the account ID from the inport and your custom business object. If there is no record here, you should create a new record. After creating a new record, you can now call your actions in order. When calling actions, you must first call ClearAttachments and then UpdateAttachments.
Then, in the “OpenLink” action, it is enough to use the OpenLink type as shown below. But you should give the Link field that fills the action in the bind parameter. So everything should be done in Embedded Component.
4. Adding new custom embedded component to TI screen
Finally, you need to add the new custom embedded component to the standard customer TI screen (COD_Account_TI). To do this, click “Add Embedded Component To Pane” on the TI screen, select your EC, and then make the required outport-inport binding as shown below.
5. Checking and testing the EC on the frontend.
Now all that’s left is to check and test your new EC on the frontend.
Click on the Attachments tab, clicking it will download and open the attachment via the Odata functionality.
In conclusion, using the OData functionality is a useful option where there is a requirement to see related attachments. The most important point in our example is to find the OData link, from which we will get the attachment, with the help of ‘OData Service Explorer’. After you get the link, you can easily view the attachments by following the steps above.