khoait / DCE.PCF

Power Apps PCF Controls Repository
GNU General Public License v3.0
49 stars 13 forks source link

PolyLookup: When adding an "Output Selected Field", the field no longer locks and says "Please save the form first" #130

Open DiogoAlex opened 3 months ago

DiogoAlex commented 3 months ago

Component

PolyLookup v1.5.0

Describe the bug

I've created a PolyLookup using a NtoN relationship to the Accounts table. I've also recetly added an "Output Selected Field" because I needed the GUID of the selected Accounts to do some work on Javascript. But, something we noticed is that, when creating a new record the field is no longer being locked and saying "Please save the form first" and lets the users select the Accounts they want. Then, when the record is created those selected Accounts are deleted

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a Poly Lookup with a NtoN relationship with any table
  2. Add an "Output Selected field"
  3. Try creating a new record
  4. Select records on the Poly Lookup
  5. Notice that after creating those records selected have disappeared

Screenshots

image image

DiogoAlex commented 3 months ago

The obvious culprit of this issue is this If, but I'm not sure if you want to remove it?: https://github.com/khoait/DCE.PCF/blob/eede997c6a57778eae9b8f46dfc1f33a7d8f8abd/PolyLookupComponent/PolyLookup/components/PolyLookupControl.tsx#L484-L486

khoait commented 3 months ago

hi @DiogoAlex, thanks for reporting. I tested from my side again and everything is working as intended as follows:

please note that, in model-driven app, we can't create associations/related records (N:N or 1:N), until the record is created first. You can see this behavior in any subgrid on the form, when you're in create form, the subgrid is read-only (in classic look) or hidden (in new look), you can't add anything to the subgrid until the form is saved.

the PolyLookup control tries to overcome this by saving the selected records as json objects to a field. but it won't associate the main record with the selected records when the form is saved, this job depends on the customizer/developer. you'll need to create some kind of logic to achieve this, it can be a cloud flow or a plugin. I have a sample plugin to deal with this scenario. Please see wiki here: https://github.com/khoait/DCE.PCF/wiki/PolyLookup#selected-items

hope it helps! cheers!