Hi,
I have a PowerApp where all data is entered in collections. When you exit the app you are promted to save the data in a SQL DB on a button click.
I've succesfully added new records in the SQL based on my collection "colPrøver". But if i try to update a row, based on GUID, I get an error that basically says "Violation of PRIMARY KEY constraint ... Cannot insert duplicate key value in object 'dbo.Samples'. The dublicate key value is (xxxxxx-xxxx-xxxx-xxxxxxxxxx)"
dbo.Samples or Samples is my SQL table and SampleId is the primary key, which i compare my colPrøver GUID against (those two are the same).
Here is my code OnSelect button:
ForAll(
colPrøver,
If(
IsBlank(
LookUp(
Samples,
SampleId = GUID(prøverGUID)
).PointId
),
Patch(
Samples,
Defaults(Samples),
{
SampleId: GUID(prøverGUID),
PointId: GUID(varBoringGUID),
SampleNo: prøverID,
SampleType: prøverTypeGeoGIS,
Depth1: prøverStartDybde,
Depth2: prøverSlutDybde,
Length: If(
IsBlank(prøverSlutDybde),
0,
Abs(prøverSlutDybde - prøverStartDybde)
),
CoreLostFromTop: 0,
Description2: "Test af PAH - Oprettet"
}
),
Patch(
Samples,
LookUp(
Samples,
SampleId = GUID(prøverGUID),
{
SampleNo: prøverID,
SampleType: prøverTypeGeoGIS,
Depth1: prøverStartDybde,
Depth2: prøverSlutDybde,
Length: If(
IsBlank(prøverSlutDybde),
0,
Abs(prøverSlutDybde - prøverStartDybde)
),
Description2: "PAH - Redigeret"
}
)
)
)
);
What am I missing, since it won't update the record if it already exist?
I've checked for dublicates on the specific GUID but i don't see any. I think is gives me that specific GUID as error, because it's the first record in colPrøver.