195
Views
1
Comments
Solved
check if a entity item already exists in database

i have a form and i want to check if the item selected on the dropdown already exist in the database. 


I have a dorpdown on the form:


I want to check if the selected option (= UserId) already exist in the table CaseConsultant:


so the userId is the selected option on the dropdown. CaseConsultant is a association class. So there can be multiple users on 1 specific CaseConsultant, however duplicate user must not be possible

2024-12-10 04-40-04
Gitansh Anand
Solution

Hi samYou can create a server action that takes UserId and CaseId as input, and inside the action, add an aggregate that fetches data from CaseConsultant with filters on UserId and CaseId. If the result is empty, that means they don't already exist, which you can set as the output. Use this function to check before creating or updating a record in the database, or you can call it in the OnChange event of the dropdown.

Also for safety you should create a unique index with UserId and CaseId together so there can't be a duplicate entry.

Thanks
Gitansh Anand

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