tsalb/lwc-utils

Collection Datatable - how to check if no records were selected (in Single selection mode)

solo-1234 opened this issue · 0 comments

I am working on a collection datatable with radio selected so the user can choose one Contact. FirstSelectedRecord is outputted to a single record var called matchedContact.

I then use the id of the selected record in an assignment later on. If the user did not select any records, the assignment fails because The flow failed to access the value for matchedContact.Id because it hasn't been set or assigned.

Attempted fix # 1: use a fault path to tell it to skip the assignment
Did not work because Assignments can't have fault paths

Attempted fix # 2: use a formula with BLANKVALUE or ISBLANK to check if a record was selected
Did not work because you can't use a record var in ISBLANK, and when I tried BLANKVALUE({!matchedContact.Id},'') I got the same error as above

Attempted fix # 3: use a decision to check if a record was selected, using matchedContact IS NULL TRUE
Did not work, it seems that even if no record was chosen, the var does not contain NULL

Attempted fix # 4: use an assignment to assign the count of matchedContact to a number var, and then let a decision check if the count is 1
Did not work because you can't use Add Count on a single record var

Attempted fix # 5: in addition to outputting firstSelectedRow from the datatable, also output selectedRows, and check the count of THAT in a decision.
THIS ONE WORKED
Screenshot:
https://i.imgur.com/iv6NuU4.png

Then I can run the assignment only if there was a contact selected in the datatable.

Hoping this can be simplified in the future!

Let me know if any other info would help. Thanks!