web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Having some issues wit...
Power Apps
Answered

Having some issues with LastSubmit variable being passed over to another form that is using a different DataSource.

(0) ShareShare
ReportReport
Posted on by 40

Hi there,

Having some issues with LastSubmit variable being passed over to another form that is using a different DataSource.

I have two Datasources and three forms. Two of the forms use the same datasource and the other form uses a different datasource. I set a variable of the first form to get the LastSubmit.ID of that form and then I use that for the other form that uses a different datasource. FormMode = New, a new form is submitted at the Personal Info screen. Then the user continues to fill out the form and depending on their answers, it will either take them to another screen that uses the third form that uses a different datasource OR it will use the answers they submitted in the subsequent screens and put their answers on a form that uses the same datasource as the first submitted form that is housed on its own screen. The problem is, that when the user attempts to enter their information and submit the thrid form, the column I try and match on is being set to 0 instead of the ID of the first submitted form, which should be using the variable that I set on the first SubmitForm button.

**Note I am no longer getting the error message that is in the GIF.**

Here is a link to the GIF workflow for this app.
https://streamable.com/k4seli

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    Hi @borowiakn ,

    Firstly, can you please consider posting your code as Text - it helps greatly when referring to and correcting it.

    The two relevant things out of your screenshots are the properties of MasterID_DataCard1 - the Default

    If(
     varMode="Edit",
     ThisItem.MasterID,
     LastContactID
    )

     and the Update

    If(
     BrowseGallery1_1.Selected.ID=0,
     Value(lastID),
     Value(BrowseGalery1_1.Selected.ID)
    )

    so the two things I initially need to know is when and where you set the Variables LastContactID and lastID.

    Also in your animation, I assume this is the "Add Person" button not working? How is this connected to the card above and what is the OnSelect of that button?

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

  • borowiakn Profile Picture
    40 on at

    @WarrenBelz - My sincere apologies, I will be sure to put the code as text.


    NextButton
    .OnSelect

    SubmitForm(ScreeningForm);
    Reset(Status_Dropdown);
    Reset(Reason);
    Reset(Type);
    Reset(EmergencyContact);
    Reset(DatePicker2);
    Reset(ProjectName_Dropdown);
    Reset(ProjectNumber);
    Reset(RoleDropDown);
    Reset(PhoneNumber);
    Reset(WorkerName);
    Reset(CompanyName);
    Reset(Emergency_Contact_Number);
    Reset(office_jobsite);
    Reset(office);
    Reset(other_craft_field);
    Reset(Non_Clayco_Dropdown);
    Set(lastID,ScreeningForm.LastSubmit.ID);
    Set(LastContactID,ScreeningForm.LastSubmit.ID);
    ResetForm(ScreeningForm);
    ResetForm(QuestionsForm);
    
    If(Reason.Selected.ProductName="Travel" || ReasonView.Text= "Travel", Navigate(Travel_Info),Navigate('Screening Questions'));
    Set(varMode,"New");
    Refresh('[dbo].[COVID_Screening_Form]');
    

    PersonalInfo-Screen.OnVisible (The form I have is on the same page but it is hidden and the fields are being referenced in the form.)

    UpdateContext({varNon: "Non-Clayco",varOffice: "Office", varJobsite: "Jobsite"});
    
    Set(statusVar,If(BrowseGallery1_1.Selected.status="true",true,false));
    ClearCollect(Role,'[dbo].[COVID_Screening_Form]');
    Reset(Status_Dropdown);
    Reset(Reason);
    Reset(Type);
    Reset(EmergencyContact);
    Reset(DatePicker2);
    Reset(ProjectName_Dropdown);
    Reset(ProjectNumber);
    Reset(RoleDropDown);
    Reset(PhoneNumber);
    Reset(WorkerName);
    Reset(CompanyName);
    Reset(Emergency_Contact_Number);
    Reset(other_craft_field);
    Reset(office);
    Reset(office_jobsite);
    
    ResetForm(ScreeningForm);
    If(varMode="Edit",EditForm(ScreeningForm),NewForm(ScreeningForm));
    Clear(RecordsCollection);
    UpdateContext({showPopup3:false});

     

    Regarding the "Add Person" button, I was using a Patch and Collect statement but was told by Microsoft that it would be easier / better to use a different datasource to store the information that is being entered seperate from the first database and to just reference the first forms ID in a corresponding column on the second database.

    AddPersonButton.OnSelect

    /*ForAll(
     Gallery1.AllItems,
     If(IsBlank(MasterID),
     Patch(
     '[dbo].[COVID_Close_Contact_Form]',
     Defaults('[dbo].[COVID_Close_Contact_Form]'),
     {
     Contact_Name: cc_Name.Text,
     Contact_Company: cc_Company.Text,
     Contact_Date: cc_Date.SelectedDate,
     Contact_Duration: cc_Duration.Text,
     Contact_Describe: cc_Describe.Text,
     Contact_Created_By: Contact_Created_By,
     MasterID: BrowseGallery1_1.Selected.ID
     }
     ),
     Patch(
     '[dbo].[COVID_Close_Contact_Form]',
     {MasterID:MasterID},
     {
     Contact_Name: cc_Name.Text,
     Contact_Company: cc_Company.Text,
     Contact_Date: cc_Date.SelectedDate,
     Contact_Duration: cc_Duration.Text,
     Contact_Describe: cc_Describe.Text,
     Contact_Created_By: Contact_Created_By,
     MasterID: lastContactID
     }
     )
    ));*/
    SubmitForm(Contact_Tracing_Form);
    Set(
     successMessage,
     "Contact Successfully added!"
    );
    
    Refresh('[dbo].[COVID_Close_Contact_Form]');
    Reset(cc_Company);
    Reset(cc_Date);
    Reset(cc_Describe);
    Reset(cc_Duration);
    Reset(cc_Name);

     

    Please let me know if you have any other questions and I will do my best to explain what the intended behavior is and what the actual behavior is.

     

    Thanks again!

  • WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    @borowiakn ,

    OK - I will point out something that may be very relevant here - FormName.LastSubmit.ID only works if the user has submitted something in that session - it will not work if you "come back in". Also in Design mode, these things have a habit of being lost when you start changing code.

    However is the whole issue the "Add Person" button is not working? In the animation, there was already a tracing record there - where did that come from?COVIDForm.jpg

    Aside from all of this, you submit the ScreeningForm, and then progress to the screen above which contains the details of possible contacts, with the relevant information at the top (for input) in a form Contact_Tracing_Form, a gallery in the lower section showing all contacts already added and an Add Person button.

    You now need the ID of the ScreeningForm to put in the MasterID of the table '[dbo].[COVID_Close_Contact_Form]'

    I use this structure on thousands on related sub-lists and the easiest way of getting the ID is to simply put in a hidden card on the ScreenForm (I will call the text box on the card txtID here) and use (put this on the Add Person button

    Set(lastID,Value(txtID.Text);
    Set(LastContactID,Value(txtID.Text);

    You then do not need any of the other logic - the ID will simply be on the form, whether it is a new one or you are editing it.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

  • borowiakn Profile Picture
    40 on at

    @WarrenBelz - Re: In the animation, there was already a tracing record there - where did that come from?

    I believe I had already added this record to the gallery so that is why it was showing up.

     

    This is the Filter that is being applied to the items in the gallery:

    Gallery1.Items (CloseContact Screen)

    Filter('[dbo].[COVID_Close_Contact_Form]',MasterID=BrowseGallery1_1.Selected.ID)

     I believe I need to somehow use an If and a Filter function on the Gallery or do a LookUp function. I need to be able to somehow say if this is a new form, then make the FormMode.New and set the MasterID = ContactLastID variable, otherwise FormMode.Edit and set MasterID = BrowseGallery1_1.Selected.ID, right?

    If I put the txtID on the ScreenForm, what values am I putting there? Am I changing the default value or anything?

    On the ScreenForm.DefaultMode

    If(varMode = "Edit", FormMode.Edit,FormMode.New)

    I know that there is probably a lot of code that can be removed from the OnVisible and OnSelect buttons happening earlier in the workflow, I currently am just not sure what I can safely remove without it breaking.

     

    Users also need to not only be able to create a NewForm entry but if the Safety Managers need to make an edit to their record, they need to be able to go to a Search screen, perform a search, click on the record, and have it navigate them to the correct record and be able to make any edits to the record as well as save any of their edits. I will try and perform that workflow and upload it here.

  • borowiakn Profile Picture
    40 on at

    @WarrenBelz - Here is the link to the workflow if a user is going to go in and make an edit to a person's record.


    https://streamable.com/f5fnyn

    The INTENDED behavior would be to ADD the person that I am entering to the Contact Tracing gallery, instead of it overwriting the previous entry. But it is at least adding the user to the Gallery, so I must be doing something halfway correct in terms of the Edit portion. 🙃 So, the effort is getting the NewForm working correctly if the user has JUST submitted a New ScreenForm in a session OR if they are editing the record and navigate to the Contact_Tracing screen and there hasn't been an entry, it needs to set the FormMode of the Contact_Tracing_Form = New, and then use the BrowseGallery1_1.Selected.ID and pass that value over to the MasterID column. And if the user is editing a record from the BrowseGallery1_1.Selected.ID, it needs to check to see if there are any rows (CountRows?) in the Gallery1 found on the Contact_Tracing screen and set the FormMode accordingly, right?

     

    I apologize if I am getting any of this wrong and understand that I am probably making it much more complex than it needs to be. Nonetheless, I appreciate your help with this, I feel like I am FINALLY getting answers on how to do this the correct way. 

  • WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    @borowiakn ,

    Lets cover these one at a time - it is very important you understand the concept of this otherwise you will not solve it. Firstly this

    Filter('[dbo].[COVID_Close_Contact_Form]',MasterID=BrowseGallery1_1.Selected.ID)

    is flawed in New mode as it is showing records from the last item selected in the Gallery (which is not the ID of the one you just created and is why a current record appeared) and adds even more reason for setting the ID from somewhere else.
    There is one thing I now realise I left out in relation to my process - where I set the new record ID. I have a global Variable varID, (you can use your lastID) which always reflects the ID of the current record being worked on. I now have a better idea for you than the hidden field (forget that one). On the OnSelect of BrowseGallery1_1

    Set(lastID,ThisItem.ID)

    On the OnSuccess of ScreenForm

    Set(lastID,Self.LastSubmit.ID)

    The Items of your Gallery

    Filter('[dbo].[COVID_Close_Contact_Form]',MasterID=lastID)​

    One other important thing here - you are using SubmitForm() for the Contact_Tracing_Form, so the value of lastID needs to be on the form.

     

    • Edit the form
    • Add the MasterID field
    • Set the Default to lastID
    • Hide the card.

    It will then add the current ID in the field MasterID of your data table '[dbo].[COVID_Close_Contact_Form]' Once you have done all of this, you do not need any other logic - lastID will always be either what you have selected from the gallery or what you just created.

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • borowiakn Profile Picture
    40 on at

    @WarrenBelz - I am tracking everything you are saying and I've taken the liberty to show you all of the OnSelect properties of the buttons found within the BrowseGallery1_1.

     

    Here are the OnSelect functions happening in the BrowseGallery1_1:

    doubleperson.png.
    OnSelect

     

    Select(Parent);
    If(CountRows(Gallery1.AllItems)=0,Set(varMode,"New"),Set(varMode,"Edit"));
    Navigate(Contact_Tracing,ScreenTransition.Fade);
    Set(varButton, true);
    Set(lastID,ThisItem.ID)

     

    QuestionsForm_OnSelect_button_BrowseGallery1_1.png.OnSelect

     

    Set(varMode,"Edit");
    Set(lastID,ThisItem.ID);
    If(Reason.Selected.ProductName = "Travel" || ReasonView.Text= "Travel", Navigate(Travel_Info),Navigate('Screening Questions'));

     

     

    PersonalInfo.png.OnSelect

     

    Select(Parent);
    Set(varMode,"Edit");
    Set(lastID,ThisItem.ID);
    Navigate('Personal Info',ScreenTransition.Fade);
    Set(varButton, true)

     

     

    I am confused about your last bit about "adding the MasterID of my data table '[dbo].[COVID_Close_Contact_Form]' ".

    I already have the MasterID on the form. The values at the top are just free-floating Text Input boxes that are then being referenced in the Contact_Tracing_Form. (See 
    Hidden_Form_Contact_Tracing.png

     

    Hopefully, this helps paint a clearer picture of what all is happening with my app. Much appreciated for your hasty replies and super helpful concept explanations! 

  • WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    @borowiakn ,

    I think we need to tackle one issue at a time - can we please put everything else including related code aside.

    The fundamental thing I see is you need to create records in your table '[dbo].[COVID_Close_Contact_Form]' which has a field MasterID that matches the corresponding ID in your table '[dbo].[COVID_Screening_Form]'.

    You simply need to always have the value of the second (ID) available so that you can either:-

    • Create new records in the close contact table with this value in the field Master ID
    • Display all records in a gallery from this table where the MasterID matches the ID of the current form record.

    Firstly, is this all correct and have you also set the lastID on the OnSuccess of the main form?

  • borowiakn Profile Picture
    40 on at

    @WarrenBelz - I applied all of the changes to my app. I performed UAT by PLAYING the app instead of performing the UAT in Edit Mode of the app with the new changes and here is what has happened so far:

    1. New Form > Fill out fields in Personal Info Screen > Submit > ScreeningForm is submitted Successfully. ✔️
    (Confirmed validation as I receive an email notifying me that it has been successfully submitted)

    2. Continue onto the QuestionsForm > Fill out fields in the corresponding fields that DO NOT take me to the Contact Tracing Screen > Submit > QuestionsForm is submitted successfully. ✔️

     

    3. Navigate to BrowseGallery1_1 > Selected previously entered record by selecting PersonalInfo.png&QuestionsForm_OnSelect_button_BrowseGallery1_1.png > Confirmed that Fields are showing previously entered values on both previously submitted QuestionsForm & ScreeningForm✔️

     

    4. From the BrowseGallery1_1 > Selected previously entered record by selecting doubleperson.png  > Contact_Tracing Screen > Entered info in fields to create New Contact > Selected Add Person > Person was added to Gallery1.  ✔️

     

    5. Went to the BrowseGallery1_1 again > Selected doubleperson.png > Contact_Tracing Screen > Gallery1 shows previously entered person > Entered info in fields to create New Contact > Selected Add Person > Person replaced previously entered person in Gallery1. ✖️

     

    6. New Form > Fill out fields in Personal Info Screen > Submit > ScreeningForm is submitted Successfully ✔️ > Continue onto the QuestionsForm > Fill out fields in the corresponding fields that DO take me to the Contact Tracing Screen > Gallery1 is showing previously entered person in Gallery1 from 5. ✖️ 

     

    6a. Entered info in fields to create New Contact > Selected Add Person > Person entered replaced entered person in Gallery1 > Selected Submit & Next Page > Entered information into final Quarantine Screen > Select Submit QuestionsForm is submitted > Navigate to BrowseGallery1_1 and Selected previously entered record by selecting doubleperson.png, Previous entry is not showing up > Select Back > Navigate to BrowseGallery1_1 and Selected previously entered record from 4 > Previous entry is showing up in Contact Tracing screen in the Gallery1.

     

    I see multiple issues that are happening.

     

    ISSUE: In 5, if the user tries to submit more than one person, the person is getting overwritten.
    PROPOSED SOLUTION: I believe that is because I have code on the Contact_Tracing_Form.OnSuccess that needs to be removed, that is as follows:

    Set(varMode , "New");ResetForm(Self)

     

    In 6, it is pulling in the previously entered person in Gallery1 but not sure what I need to do in order to fix that. 

     

    I know that I need to stay focused on just ONE thing, but I am unable to do that because there are multiple paths that lead you in different directions, so I am just trying to be thorough. 

     

    Thank you @WarrenBelz again and looking forward to your reply.

  • borowiakn Profile Picture
    40 on at

    @WarrenBelz - I believe I didn't Publish your changes in the app, so I republished the app and ran it again with different results from above.

    1. New Form > Fill out fields in Personal Info Screen > Submit > ScreeningForm is submitted Successfully. 

    (Confirmed validation as I receive an email notifying me that it has been successfully submitted)

    2. Continue onto the QuestionsForm > Fill out fields in the corresponding fields that DO NOT take me to the Contact Tracing Screen > Submit > ERROR: There was a problem saving your changes. The data source may be invalid.


    Going to wait to hear back from you so we can stay focused on one issue at a time.

     


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard