cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sanderson82
Level: Powered On

Email Excel Attachment (File created in flow and saved in OneDrive)

Hi, 
I have an app when the first button is pressed it runs a flow which creates an excel file from a template and adds a blank table (Labels) which is connected as a datasource in my app.
On the next screen the user adds information to a collection which is then patched to the excel table.  Idea is that this excel file is then sent in an email using another flow.

My issue is I'm getting a "file is locked for editing" error.  It seems that although the initial flow has created the file it is still holding a "lock" on the file.  Having looked at other posts in the forum I believe  this is a known issue when using excel files in OneDrive?

 

Is anyone aware of a fix for this?  Is it possible to generate and e-mail an excel file with collection data from within PowerApps to bypass using OneDrive?

 

Many thanks for any help

6 REPLIES 6
Dual Super User
Dual Super User

Re: Email Excel Attachment (File created in flow and saved in OneDrive)

Hi @sanderson82 

 

Why not just have the excel template as part of the PowerApp (import from excel) rather than connecting to the template

 

And then once the data is popluated in a colleciton by the user, just post that over to Flow, which can use the data to generate the excel file

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

sanderson82
Level: Powered On

Re: Email Excel Attachment (File created in flow and saved in OneDrive)

Hi @RezaDorrani 

Thanks for the info, could you elaborate a little further?  I'm assuming the excel file I pull in still needs to have a blank table with the column names?  This is currently my code to patch data from my collection to the "Labels" table in excel

Refresh(Labels);
ForAll(
    Made_Items.AllItems,
    Patch(
        Labels,
        Defaults(Labels),
        {
            Date: I_PDate.SelectedDate,
            CNum: Left(Contract,5),
            Contract: Mid(Contract,9),
            Unit: Unit,
            Volume: Volume,
            Weight: Weight,
            Sequence: If(Len(Sequence)=1,"00"&Sequence, If(Len(Sequence)=2,"0"&Sequence, If(Len(Sequence)=3,Sequence,false ) ) ),
            Barcode: Barcode
        }
    )
); Navigate(Summary,Fade)

I then run a flow on a button on the next screen to get the updated excel file from OneDrive and email it.

 

I've attemped to use "Import from Excel" however it tells me that the data source is read-only so I can't patch to it

Community Support Team
Community Support Team

Re: Email Excel Attachment (File created in flow and saved in OneDrive)

Hi @sanderson82 ,

Could you please share a screenshot about your flow's configuration?

How do you add the Excel table as data source in your app?

Do you add the Excel table as data source dynamically within your app?

 

Based on the error message that you mentioned, I afraid that there is no way to fix it within PowerApps app. As an alternative solution, you could consider merge the "Create file" operation and "Patching data to Excel table" operation into one step rather than twp.

 

In other words, you just need to add single one button in the second screen (next screen) of app, when pressing it to fire a flow and pass the user entry collection to your flow. Within your flow, you could add actions to create a Excel table firtsly, and then add actions to save data passed from your app into the new added Excel table, and then send an email along with the Excel file.

 

More details about passing a JSON data from an app to a flow, please check the following threads

https://powerusers.microsoft.com/t5/General-Discussion/Capture-Image-and-Save-as-Attachment/m-p/3608...

https://powerusers.microsoft.com/t5/Building-PowerApps-Formerly/Save-a-multiples-rows-of-items-in-a-...

 

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.
sanderson82
Level: Powered On

Re: Email Excel Attachment (File created in flow and saved in OneDrive)

Hi @v-xida-msft
Initially I had a flow which created the excel file for meFlow 1.png

I then had this excel file connected to my app as a data source so that I could patch to it, then another flow at the end to email the file content as an excel file

Flow 2.png

 

However this method gives me errors that there is a lock in the file as I am using OneDrive

Community Support Team
Community Support Team

Re: Email Excel Attachment (File created in flow and saved in OneDrive)

Hi @sanderson82 ,

Have you taken a try with the solution I mentioned above?

 

Please make sure the 'SecondFlow'.Run(...) formula executed after your Patch formula. On your side, please modify your formula as below:

ForAll(
    Made_Items.AllItems,
    Patch(
        Labels,
        Defaults(Labels),
        {
            Date: I_PDate.SelectedDate,
            CNum: Left(Contract,5),
            Contract: Mid(Contract,9),
            Unit: Unit,
            Volume: Volume,
            Weight: Weight,
            Sequence: If(Len(Sequence)=1,"00"&Sequence, If(Len(Sequence)=2,"0"&Sequence, If(Len(Sequence)=3,Sequence,false ) ) ),
            Barcode: Barcode
        }
    )
);
Refresh(Labels);
'SecondFlow'.Run(...); /* <-- Fire your second flow after executing the Patch formula completely */
Navigate(Summary,Fade)

If the issue still exists, please consider take a try with above solution I mentioned, 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.
sanderson82
Level: Powered On

Re: Email Excel Attachment (File created in flow and saved in OneDrive)

Hi @v-xida-msft I've modified my flows so that I don't create a file at the start.  I just use the same file.  My second flow deletes all the rows at the end so it is blank for the next run.

 

My issue now is that I get a file lock error when the app starts, I'm assuming as it tries to refresh all data sources including "Labels".  If I leave it for say up to 1 hour and run the app again everything works fine

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 369 members 6,557 guests
Please welcome our newest community members: