I have a button that validates certain requirements before saving data. When saving, I need the data fields to be saved in two different tables:
First Table: This table should always update existing rows. For example, if a customer reassesses a specific product, the assessment should be updated with the latest data, ensuring only one assessment per product is saved. This functionality currently works as intended in my code.
Second Table: This table should always save a new assessment, regardless of whether an assessment for that specific product already exists. However, I am encountering an error message: "Element already exists on server." I have tried various solutions, including loops and the Collect
function, but the issue persists.
I would greatly appreciate any help in resolving this issue!
Collect(
All_assessments;
{
ForAll(
[1],
Collect(
All_assessments;
If(
IsBlank(Field1.Selected.Value);
Notify("Please select a value before saving"; NotificationType.Error);
false;;
If(
(Field1.Selected.Value = "Option1" Or Field1.Selected.Value = "Option2") And IsBlank(Field2.Text);
Notify("For Option1 and Option2, please provide a justification in the comment section before saving"; NotificationType.Error);
false;;
If(
IsBlank(Field3.Selected.Value) And IsBlank(Field4.Selected.Value) And IsBlank(Field5.Selected.Value) And IsBlank(Field6.Selected.Value);
Notify("Please select at least one option before saving"; NotificationType.Error);
false;;
If(
IsBlank(Field7.Text);
Notify("Field7 cannot be blank before saving"; NotificationType.Error);
false;;
If(
IsBlank(Field8.Text) Or IsBlank(LookUp(Table1; ID_Field = Field8.Text));
Notify("Field8 does not exist"; NotificationType.Error);
false;;
Patch(
Table1;
LookUp(Table1; ID_Field = Field8.Text);
{
Field1: Field1.Selected.Value;
Field3: Field3.Selected.Value;
Field4: Field4.Selected.Value;
Field5: Field5.Selected.Value;
Field6: Field6.Selected.Value;
Field2: Field2.Text;
Field7: Field7.Text;
Field9: Field9.Text
}
);;
Patch(
Table2;
Defaults(Table2);
{
ID_Field: Field8.Text;
Field1: Field1.Selected.Value;
Field3: Field3.Selected.Value;
Field4: Field4.Selected.Value;
Field5: Field5.Selected.Value;
Field6: Field6.Selected.Value;
Field2: Field2.Text;
Field7: Field7.Text;
Field9: Field9.Text
}
);;
If(
!IsEmpty(Errors(Table2));
Notify("Error saving to Table2: " & First(Errors(Table2)).Message; NotificationType.Error);
Notify("Record successfully saved"; NotificationType.Success)
);;
Reset(Field8);;
Reset(Field1);;
Reset(Field3);;
Reset(Field4);;
Reset(Field5);;
Reset(Field6);;
Reset(Field2)
)
)
)
)
)
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.