I am building an offline powerapp for our sales department to use when internet connectivity is limited. I have managed to build an app where customer data and contacts are added to two collections (i.e. colCustomerData, and colContactsData). They are tied to two SP Lists called Customers and Contacts. The one-to-many relationship is established between the two lists using ID from the Customers and RefID from Contacts. Everything works as expected within the app when users add customers and contacts, however, the problem I'm having is when it comes time to sync (patch) the data back to the datasources, in this respect the two SP lists (Customers, and Contacts), and maintain the relationship.
This is the desired result I am seeking and hopefully one of you gurus can help.
When the user enters more than one customer in the app, and associates several contacts to that customer, when they are online and sync the data back to SharePoint, I want the app to be able to enter the customer and contacts for each customer and its associated contacts. Additionally, I am using an add and update button to add or update the record in the collections.
Contacts Add Button:
OnSelect: Collect(colContactsData, {Title: Contact_DataCard1.Update, Contact_x0020_Phone: 'Contact Phone_DataCard1'.Update, Contact_x0020_Email: 'Contact Email_DataCard1'.Update, RefID: varRecord.ID});SaveData(colContactsData, "SavedContactData");ResetForm(ContactsEditForm);NewForm(ContactsEditForm)
Customer Add Button:
OnSelect: Collect(colCustomersData, {Title: Customer_DataCard2.Update, Address: Address_DataCard2.Update, PhoneNumber: Phone_DataCard2.Update, Salesperson0: Salesperson.Selected, ID: CountRows(colCustomerData)+1});ResetForm(CustomerEditForm);SaveData(colCustomerData, "SavedCustomerData");NewForm(CustomerEditForm)
I have tried several Patch, ForAll, Lookup combinations but can't seem to wrap my head around how to get this to work. Here is what works for one record:
Set(varID,Patch(Customers,Defaults(colCustomerData),CustomerEditForm.Updates).ID);Patch(Contacts,ForAll(colContactsData,{'Ref ID': varID, Title: Title, ContactPhone: ContactPhone, ContactEmail: ContactEmail}))
I am trying to get the app to work for all records. I am new to this forum so please excuse me if this has already been addressed. I have been Googling for days and can't seem to find the precise answer to my problem. Thanks for all that you do. Best Regards.