cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ruth
Level: Powered On

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
ruth
Level: Powered On

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

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
Power Apps Staff CarlosFigueira
Power Apps Staff

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

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.

ruth
Level: Powered On

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

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.

ruth
Level: Powered On

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

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
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (6,024)