Hi @pkumar ,
Have you set "Auto-Increment" (Identity(1,1)) for the ID column in your '[dbo].[ContractInformation]' table?
Please consider take a try with the following workaround:
Set the OnSelect property of "New" button to following:
NewForm(EditForm1);
Navigate(EditScreen);
Clear(ContractInformation);
Collect(
ContractInformation,
{
ID: "",
ContractName: "",
Position: "",
CompanyName: "",
ContactNumber: "",
Incident_ID: ""
}
)
Set the OnSelect property of the "Edit" button to following:
EditForm(EditForm1);
Navigate(EditScreen);
Clear(ContractInformation);
ForAll(
'[dbo].[ContractInformation]',
Collect(
ContractInformation,
{
ID: '[dbo].[ContractInformation]'[@ID],
ContractName: '[dbo].[ContractInformation]'[@ContractName],
Position: '[dbo].[ContractInformation]'[@Position],
CompanyName: '[dbo].[ContractInformation]'[@CompanyName],
ContactNumber: '[dbo].[ContractInformation]'[@ContactNumber],
Incident_ID: '[dbo].[ContractInformation]'[@Incident_ID]
}
)
)
Within your Edit screen, set the Items property of the Repeating Table Gallery to following (filter ContractInfomation records based on foreign key😞
If(
EditForm1.Mode = FormMode.New,
ContractInformation,
Filter(ContractInformation, Incident_ID = IncidentReportGallery.Selected.ID)
)
Note: I assume that you use a Gallery to list all available Incident report records.
Set the OnSuccess property of the Edit form to following:
ForAll(
Filter(RepeatingTableGalery.AllItems, !IsBlank(Contract_Name_2.Text)),
If(
IsBlank(LookUp('[dbo].[ContractInformation]', ContractName = Contract_Name_2.Text && Position = Contract_Position_2.Text && CompanyName = Company_Name_2.Text && ContactNumber = ContactNumber_2.Text)),
Patch(
'[dbo].[ContractInformation]',
Defaults('[dbo].[ContractInformation]'),
{
Incident_ID: EditForm1.LastSubmit.ID,
ContractName: Contract_Name_2.Text,
Position: Contract_Position_2.Text,
CompanyName: Company_Name_2.Text,
ContactNumber: ContactNumber_2.Text
}
)
)
);
If you do not set the "Auto-Increment" property for the "ID" column in your '[dbo].[ContractInformation]' table, please consider modify above formula as below:
ForAll(
Filter(RepeatingTableGalery.AllItems, !IsBlank(Contract_Name_2.Text)),
If(
IsBlank(LookUp('[dbo].[ContractInformation]', ContractName = Contract_Name_2.Text && Position = Contract_Position_2.Text && CompanyName = Company_Name_2.Text && ContactNumber = ContactNumber_2.Text)),
Patch(
'[dbo].[ContractInformation]',
Defaults('[dbo].[ContractInformation]'),
{
ID: Last('[dbo].[ContractInformation]').ID + 1, // Add formula here
Incident_ID: EditForm1.LastSubmit.ID,
ContractName: Contract_Name_2.Text,
Position: Contract_Position_2.Text,
CompanyName: Company_Name_2.Text,
ContactNumber: ContactNumber_2.Text
}
)
)
);
Best regards,