I have the below code and it is throwing the error: "The data source you supplied is invalid", however the code works as expected without error.
This wouldn't be problem, however I want different actions based on if there were error patching or not. This is causing the Errors() funtion to always detect errors, when in reality the patch is going through to the DB just fine.
One thing I found online was to specify the record I want to patch but that seems redundant and the code actually works as is.
If(!IsEmpty(toUpdateSmall),
If(
IsEmpty(
Errors(Patch('[dbo].[ForecastData]',toUpdateSmall))
),
Notify("Database toUpdateSmall write succesful", Success);
//put update collection code here
,Notify("Database toUpdateSmall write NOT succesful", Error);
ForAll(RenameColumns(toUpdateSmall, "ItemId", "ItemId2", "ForecastMonth", "ForecastMonth2", "ForecastYear", "ForecastYear2", "SalespersonId", "SalespersonId2", "CustomerKeyAccountParentId", "CustomerKeyAccountParentId2", "CurrentForecastQty", "CurrentForecastQty2"), Update(datasource_temp2, LookUp(datasource_temp2, SalespersonId2 = SalespersonId && ItemId2 = ItemId && CustomerKeyAccountParentId = CustomerKeyAccountParentId2 && ForecastMonth = ForecastMonth2 && ForecastYear = ForecastYear2), {CurrentForecastQty:CurrentForecastQty2, CustomerKeyAccountParentId:CustomerKeyAccountParentId2, ForecastMonth:ForecastMonth2, ForecastYear:ForecastYear2, ItemId:ItemId2, SalespersonId:SalespersonId2}))
));
Solved! Go to Solution.
Hi @samuelJ ,
Based on the formula you provided, I think there is something wrong with the Errors function that you mentioned.
The first argument of the Errors function is required to provide a data source rather than a record, the result the Patch function returned is a record value.
I have made a test on my side, please consider modify your formula as below:
If(!IsEmpty(toUpdateSmall),
If(
IsEmpty(
Errors('[dbo].[ForecastData]', Patch('[dbo].[ForecastData]', toUpdateSmall)) // Modify formula here
),
Notify("Database toUpdateSmall write succesful", Success);
//put update collection code here
,Notify("Database toUpdateSmall write NOT succesful", Error);
ForAll(RenameColumns(toUpdateSmall, "ItemId", "ItemId2", "ForecastMonth", "ForecastMonth2", "ForecastYear", "ForecastYear2", "SalespersonId", "SalespersonId2", "CustomerKeyAccountParentId", "CustomerKeyAccountParentId2", "CurrentForecastQty", "CurrentForecastQty2"), Update(datasource_temp2, LookUp(datasource_temp2, SalespersonId2 = SalespersonId && ItemId2 = ItemId && CustomerKeyAccountParentId = CustomerKeyAccountParentId2 && ForecastMonth = ForecastMonth2 && ForecastYear = ForecastYear2), {CurrentForecastQty:CurrentForecastQty2, CustomerKeyAccountParentId:CustomerKeyAccountParentId2, ForecastMonth:ForecastMonth2, ForecastYear:ForecastYear2, ItemId:ItemId2, SalespersonId:SalespersonId2}))
));
or
If(
!IsEmpty(toUpdateSmall),
Patch('[dbo].[ForecastData]', toUpdateSmall);
If(
IsEmpty(
Errors('[dbo].[ForecastData]') // Modify formula here
),
Notify("Database toUpdateSmall write succesful", Success);
//put update collection code here
,Notify("Database toUpdateSmall write NOT succesful", Error);
ForAll(RenameColumns(toUpdateSmall, "ItemId", "ItemId2", "ForecastMonth", "ForecastMonth2", "ForecastYear", "ForecastYear2", "SalespersonId", "SalespersonId2", "CustomerKeyAccountParentId", "CustomerKeyAccountParentId2", "CurrentForecastQty", "CurrentForecastQty2"), Update(datasource_temp2, LookUp(datasource_temp2, SalespersonId2 = SalespersonId && ItemId2 = ItemId && CustomerKeyAccountParentId = CustomerKeyAccountParentId2 && ForecastMonth = ForecastMonth2 && ForecastYear = ForecastYear2), {CurrentForecastQty:CurrentForecastQty2, CustomerKeyAccountParentId:CustomerKeyAccountParentId2, ForecastMonth:ForecastMonth2, ForecastYear:ForecastYear2, ItemId:ItemId2, SalespersonId:SalespersonId2}))
));
Please consider take a try with above formula, then check if the issue is solved.
Best regards,
I ran into this same problem. The issue, as far as I can tell, is that the ForAll can't be nestled that deeply in your formula. I rewrote a similar formula to you with ForAll at the start and it works fine.
Thanks @dyee4614 , However, even if I take the forAll() code out completely, the error still persists.
Hi @samuelJ ,
Based on the formula you provided, I think there is something wrong with the Errors function that you mentioned.
The first argument of the Errors function is required to provide a data source rather than a record, the result the Patch function returned is a record value.
I have made a test on my side, please consider modify your formula as below:
If(!IsEmpty(toUpdateSmall),
If(
IsEmpty(
Errors('[dbo].[ForecastData]', Patch('[dbo].[ForecastData]', toUpdateSmall)) // Modify formula here
),
Notify("Database toUpdateSmall write succesful", Success);
//put update collection code here
,Notify("Database toUpdateSmall write NOT succesful", Error);
ForAll(RenameColumns(toUpdateSmall, "ItemId", "ItemId2", "ForecastMonth", "ForecastMonth2", "ForecastYear", "ForecastYear2", "SalespersonId", "SalespersonId2", "CustomerKeyAccountParentId", "CustomerKeyAccountParentId2", "CurrentForecastQty", "CurrentForecastQty2"), Update(datasource_temp2, LookUp(datasource_temp2, SalespersonId2 = SalespersonId && ItemId2 = ItemId && CustomerKeyAccountParentId = CustomerKeyAccountParentId2 && ForecastMonth = ForecastMonth2 && ForecastYear = ForecastYear2), {CurrentForecastQty:CurrentForecastQty2, CustomerKeyAccountParentId:CustomerKeyAccountParentId2, ForecastMonth:ForecastMonth2, ForecastYear:ForecastYear2, ItemId:ItemId2, SalespersonId:SalespersonId2}))
));
or
If(
!IsEmpty(toUpdateSmall),
Patch('[dbo].[ForecastData]', toUpdateSmall);
If(
IsEmpty(
Errors('[dbo].[ForecastData]') // Modify formula here
),
Notify("Database toUpdateSmall write succesful", Success);
//put update collection code here
,Notify("Database toUpdateSmall write NOT succesful", Error);
ForAll(RenameColumns(toUpdateSmall, "ItemId", "ItemId2", "ForecastMonth", "ForecastMonth2", "ForecastYear", "ForecastYear2", "SalespersonId", "SalespersonId2", "CustomerKeyAccountParentId", "CustomerKeyAccountParentId2", "CurrentForecastQty", "CurrentForecastQty2"), Update(datasource_temp2, LookUp(datasource_temp2, SalespersonId2 = SalespersonId && ItemId2 = ItemId && CustomerKeyAccountParentId = CustomerKeyAccountParentId2 && ForecastMonth = ForecastMonth2 && ForecastYear = ForecastYear2), {CurrentForecastQty:CurrentForecastQty2, CustomerKeyAccountParentId:CustomerKeyAccountParentId2, ForecastMonth:ForecastMonth2, ForecastYear:ForecastYear2, ItemId:ItemId2, SalespersonId:SalespersonId2}))
));
Please consider take a try with above formula, then check if the issue is solved.
Best regards,
@v-xida-msft thanks for replying,
The first solution offered provides syntactical errors. The second solution seems to do the trick though! One follow up question, will this catch errors if we hit the SQL Server limitation of 100 API calls within 10 seconds?