Dear community below I have provided my current submit form formula and support images. Right now this formula works, because I have manually entered a list of names within the powerapps trigger parameter as per the image. The problem is that it is a manual procedure and anytime a new name is added to my sharepoint list, i have to add that name manually into powerautomate which i really want to avoid doing. Is there a way for this not to happen, so that the flow works regardless? In that the flow should work without having to manually insert names all the time, contrary to my current set-up. I already have a list of names in sharepoint connected to the Name field given by the formula: Name_1.SelectedItems, but unless that name is listed in the trigger parameter as well, it won't work. Therefore, a name has to always be amongst the list and i would rather the flow not be dependent on hard coded names.
To specify, the submit button that holds the formula below, submits to another sharepoint list which acts as my database. The way that my current flow and formula is set up, works because I have manually entered all the names present in both the sharepoint list that houses only the names and in the parameter of the powerapps trigger. Unless the same names are present in the trigger parameter, the form will not submit thus the flow will not work. So, keeping all else equal I was wondering if there is a way to have the flow work, the submit button work and save the record to my database without having to hard code a list of names in powerautomate all the time. I'm thinking that the flow should check/loop through the names in my sharepoint list with only the names, instead of relying on the hard coded names inserted into the trigger. Otherwise the process becomes too manual and requires someone else in the future who is not me, to access back-end features all the time, and that is not feasible.
If I get rid of all the names from the trigger the flow won't work because powerapps will tell me that the name is not defined in the enum, which goes to show that the current set up is too dependent on hard coded names. As you can see from one of the images attached, I have inserted a list of names and the apply to each loops through those names and creates a new row every time the form is submitted, which is fine I don't mind that because the name field is a drop down menu that allows for multiple selection, so creating a new row for each name keeps the database more tidy. However as you can see from the images, the flow relies on hard coded names, and every time a new name is inserted into the sharepoint list, I or whomever will have to refresh the sharepoint connection in powerapps, open the flow and add that name to the list and then refresh the powerautomate connection in powerapps and then the form can be used. I hope the outcome of what I want to achieve is more clear now. It should only be a question of modifying the powerautomate flow.
// Mark that a submit attempt has occurred
Set(SubmitAttempted; true);;
// If the required fields are filled
If(
// If the required fields are filled (for new record or update)
!IsBlank(Name_1.SelectedItems) &&
!IsBlank(Date_1.SelectedDate) &&
!IsBlank(Date_2.SelectedDate) &&
!IsBlank(Time_1.Text) &&
!IsBlank(Time_2.Text) &&
!IsBlank(DepartureRoute_1.Text) &&
!IsBlank(DepartureFlightNumber_1.Text) &&
!IsBlank(ReturnRoute_1.Text) &&
!IsBlank(ReturnFlightNumber_1.Text);
// New Record Logic (whether checkbox is checked or not)
If(
Form1.Mode = FormMode.New; // New record creation logic
// Create a new record using ForAll for Name_1.SelectedItems
ForAll(
Name_1.SelectedItems;
'EasyTravelFlow_ORG.(Flights)'.Run(
Table({Value: ThisRecord.Value});
Department_1.Text; // No need for Switch, just use mapped field in Default
Classification_1.Text; // Classification mapped in Default as well
// Date and time fields
Text(DateAdd(Date_1.SelectedDate; 0; TimeUnit.Hours); "yyyy-mm-dd");
Time_1.Text;
DepartureRoute_1.Text;
DepartureFlightNumber_1.Text;
Text(DateAdd(Date_2.SelectedDate; 0; TimeUnit.Hours); "yyyy-mm-dd");
Time_2.Text;
ReturnRoute_1.Text;
ReturnFlightNumber_1.Text;
If(IsBlank(Cost_1.Text) || Len(Trim(Cost_1.Text)) = 0; 0; Value(Cost_1.Text));
Round_1.Text;
If(IsBlank(PONumber_1.Text) || Len(Trim(PONumber_1.Text)) = 0; "N/A"; PONumber_1.Text);
CodDip1.Text;
CodFatt1.Text;
CodCont1.Text;
If(IsBlank(Imptetotal1.Text) || Len(Trim(Imptetotal1.Text)) = 0; 0; Value(Imptetotal1.Text))
)
);;
);;
// Update Logic for Existing Record (in edit mode)
If(
Form1.Mode = FormMode.Edit; // Update logic for selected record
Patch(
'Flights Database ORG. (test)'; // Data source to update
Gallery1.Selected; // Selected record in the gallery
{
// Fields to update
Departure: Date_1.SelectedDate;
'Department (Auto Populates)': Department_1.Text; // Department mapped to the field
'Classification (Auto Populates) ': Classification_1.Text; // Classification mapped to the field
Return: Date_2.SelectedDate;
'Departure Time': Time_1.Text;
'Return Time': Time_2.Text;
'Departure Route': DepartureRoute_1.Text;
'Departure Flight Number': DepartureFlightNumber_1.Text;
'Return Route': ReturnRoute_1.Text;
'Return Flight Number': ReturnFlightNumber_1.Text;
'Ticket Cost/person (€)': If(IsBlank(Cost_1.Text) || Len(Trim(Cost_1.Text)) = 0; 0; Value(Cost_1.Text));
'Round (Auto Populates)': Round_1.Text;
'PO Number': If(IsBlank(PONumber_1.Text) || Len(Trim(PONumber_1.Text)) = 0; "N/A"; PONumber_1.Text);
Name: Name_1.Selected;
'Cod. Dipendente': CodDip1.Text;
'Cod. Fattura': CodFatt1.Text;
'Cod. Contabilità ': CodCont1.Text;
'Impte total': If(IsBlank(Imptetotal1.Text) || Len(Trim(Imptetotal1.Text)) = 0; 0; Value(Imptetotal1.Text))
}
);;
);;
// Reset the form and update the gallery after submission
ResetForm(Form1) &
Set(varGalDefault; Blank()) &
Set(varGalDefault; {}) &
Reset(Timer_1) &
SubmitForm(Form1) &
UpdateContext({showToast: true}) &
Refresh('Flights Database ORG. (test)');
// If validation fails, keep SubmitAttempted true so fields highlight
false
);;