SAP Knowledge Base Article - Public

2640170 - Custom Validation in Attachment Does Not Work as Expected

Symptom

You are using the standard functionality of attachments and implemented a custom validation to verify the files to be attached.
You have implemented this scenario in the ABC (ABC stands for the view name) view of the XYZ (XYZ stands for the work center name) work center.
When adding a new attachment to an instance which is already created your event before save is not triggered as you expects.

Environment

  • SAP Cloud for Customer
  • SAP Business ByDesign
  • SAP Cloud Applications Studio

Reproducing the Issue

  1. Go to XYZ work center.
  2. Open ABC view.
  3. Select an entry.
  4. Click on Edit.
  5. In the Attachments Session click on Add.
  6. Upload an inconsistent file (according to the validation you created).
  7. Click on Save.
  8. Your entries will be saved and the event before save will not be called.

If you modify the value of any field in the header of this entry and click on Save, the event before save will be triggered. In this case the validation will occur for all the files you have attached.

Cause

The framework does not count the change in the attachment folder as a change in the instance, hence the validations are not called.
Attachment Folder is an association within the custom BO(stands for Business Object) and just changing the content of it would not trigger the validations once the custom BO Instance is already created.
If you use the Trace Funtion on SDK while trying to add an attachment in an already created instance you will see in the trace results that anything was called and because of it the save was successful.

Resolution

If a field on Root Node is changed before clicking on save, the validations are called and the scenario works as expected. It happens because when you change a field in Root Node the framework understands the instance was changed and the validations happen for the entire instance and its associations, hence the validations on the attachments must happen again.

To overcome this scenario some modeling adjustments on ABSL would be needed.

See Also

In case of further questions on ABSL Implementation, please reach out to our SAP Cloud Applications Studio Community.

Keywords

Attachment; Validation; Before; Save; , KBA , AP-RC-BDS-BO , ByDesign Studio BO definition/generation , How To

Product

SAP Business ByDesign all versions ; SAP Cloud Applications Studio all versions ; SAP Cloud for Customer add-ins all versions ; SAP Cloud for Customer core applications all versions