cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
samuelJ
Responsive Resident
Responsive Resident

"The data source you supplied is invalid" yet the patch works

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.  

patch.PNG

 

 

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}))

));

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
dyee4614
Helper V
Helper V

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.

samuelJ
Responsive Resident
Responsive Resident

Thanks @dyee4614 , However, even if I take the forAll() code out completely, the error still persists.  

 

v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@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?  

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,415)