21
Views
3
Comments
Solved
Delete record with two entities (One to many relationship) in one click

Please refer to Mainflow\JobMainInfo

In this screen, I have added delete button, But the table structure here is one JobMaintenance has many JobDetailTasks, and if there is job tasks here the job cannot be deleted as below.

Would please help check "Delete Job" Action and guide how to delete the tasks inside if I click delete the job here in one click. Thanks.

JobManagementPOC(Reference1005).oml
Solution

Hi @Winnie Lam ,

You can do following steps:

  • On action DeleteJobOnclick, ceate an input paramter. Pass the JobMaintenance Id.
  •  Create a server action like below. Use aggregate to get all the Job tasks details for this JobMaintenance Id. Delete them all using for loop.
  • Call that server action to your screen action DeleteJob. Then delete the JobMaintenance record.Note: Make sure to follow the best practice and remove the warnings
Solution

Hello Winnie,

If you have Protect Delete rule for reference key then its not passible to delete the record.

https://success.outsystems.com/documentation/11/developing_an_application/use_data/data_modeling/entity_relationships/delete_rules/ 

You can check above documentation on delete rule.

As mentioned by Puja, you need to delete the record for reference key first then the other record. 

Best Regards,

Komal

Solution

Hi @Winnie Lam ,

You can do following steps:

  • On action DeleteJobOnclick, ceate an input paramter. Pass the JobMaintenance Id.
  •  Create a server action like below. Use aggregate to get all the Job tasks details for this JobMaintenance Id. Delete them all using for loop.
  • Call that server action to your screen action DeleteJob. Then delete the JobMaintenance record.Note: Make sure to follow the best practice and remove the warnings

Hello @Winnie Lam ,

I have analyzed your OML. First delete all the JobTasks corresponding to the maintenance id. Then delete the JobMaintenance. It will not give you any errors.

I hope this will help you!

Have a great day

Thanks & Regards,

Sudip Pal

Solution

Hello Winnie,

If you have Protect Delete rule for reference key then its not passible to delete the record.

https://success.outsystems.com/documentation/11/developing_an_application/use_data/data_modeling/entity_relationships/delete_rules/ 

You can check above documentation on delete rule.

As mentioned by Puja, you need to delete the record for reference key first then the other record. 

Best Regards,

Komal

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.