cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ruth
Helper IV
Helper IV

How to view record if found, otherwise, set to new

I'm displaying a list of records from SP ListA.  When a row is selected, I'd like to check if an associated record exists in ListB.  If it does exist, then I'd like to display the fields in a form and edit.  if it doesn't exist, I'd like start a new form and set colA and colB of ListB to selected values in ListA.

 

I'm not sure of the best approach but I have created a table which lists ListA and 2 forms - 1 Edit and 1 New.  For now, I've hiddent both forms so that I can test the following code, but of course, it doesn't work:

 

If(LookUp(ListB,FAID = dtblListA.Selected.ID),"Found")="Found", frmEdit.Visible = true,frmNew.Visible=true) 

 

When I do have the new form visible, I am able to set colA and colB of ListB to the selected values in ListA.  But, I can't check if the record exists and display the appropriate form.  And, I can't set the values if the record is found.

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

After trouble-shooting a bit more, it doesn't seem like the "if" statement was working.  I modified as follows and it works nicely:

 

Set(ListBItem, LookUp(ListB, FAID = dtblListA.Selected.ID));
If(LookUp(ListBItem,FAID=dtblListA.Selected.ID,"Found")="Found",EditForm(frmListB),NewForm(frmListB))

 

Not sure why the "isEmpty" condition wouldn't work

View solution in original post

3 REPLIES 3
CarlosFigueira
Power Apps
Power Apps

You can have a single form, and depending on whether you want to edit or create a new item, you can call the NewForm or EditForm function on it. The expression would be somewhat like this (on a button selection, or on a screen visible):

Set(listBItem, LookUp(ListB, FAID = dtblListA.Selected.ID));
If(
    IsEmpty(listBItem),
    NewForm(formEditAndNew),
    EditForm(formEditAndNew))

You would also set the 'Item' property of that form to the 'listBItem' variable - this way when you put the form in edit mode, it will show the values for that item to be edited.

Thanks for the quick response.  I see what I was doing wrong.  But now I'm getting sporadic results.  At first both conditions worked, but then I continued to select rows and I was always able to display a matching record, but then when I selected a row where there wasn't a match, I received no data to display.  When I was in the programming mode and I selected "Alt" and the record, both conditions worked.

 

I'm editing this response as I published my app and ran it.  I refreshed the screen and selected a record, it shows but then I get a message "Getting Data" but nothing displays.

After trouble-shooting a bit more, it doesn't seem like the "if" statement was working.  I modified as follows and it works nicely:

 

Set(ListBItem, LookUp(ListB, FAID = dtblListA.Selected.ID));
If(LookUp(ListBItem,FAID=dtblListA.Selected.ID,"Found")="Found",EditForm(frmListB),NewForm(frmListB))

 

Not sure why the "isEmpty" condition wouldn't work

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (26,279)