Forum Discussion
Flow Action - Convert Word Document to PDF
I'm trying to use the Convert Word Document to PDF action in a Flow. There are three parameters that have to be entered:
- Location - the SharePoint Site
- Document Library - Library where the document is located.
- File - The document to convert
The parameter that I'm having an issue with is the File. The flow works if I choose the specific document from the library but I want it to be dynamic so that when the user starts a Flow on the document it will convert that one, so I don't want to hardcode the document name.
For the File property I'm using the property from a previous step with the file name called File name with extension.
When I run the flow I get an error, "There was an error accessing the file. Please try again or select a different file."
Can I not use dynamic content for the File property?
Thanks
35 Replies
- saad121212Copper Contributor
Hello everyone,
I am trying to convert word into PDF using the same action but when I try to pass dynamic value in "Document Library" parameter, I am getting error.{
"status": 404,
"message": "The selected file doesn't exist, please select a valid file and drive.\r\nclientRequestId: 7c6b5a78-ff64-4156-b95c-19aa5423a60b",
"error": {
"message": "The selected file doesn't exist, please select a valid file and drive."
},
"source": "wordonlinebusiness-scus.azconn-scus-001.p.azurewebsites.net"
}
But when I chose it from dropdown, everything goes well.
My requirement is to choose document library dynamically because we create new libraries through Power Automate.Please let me know how can I convert word into PDF by passing dynamic value into Document Library parameter or is there any alternate solution?
Thanks - AliS2445Copper ContributorHi guys, I was able to resolve this issue !!!
The problem is with the extended path format which you get from a dynamic value of sharepoint file.
My flow basically includes creating a file at sharepoint first, and i'm getting the path from the outputs of body/Path of "Create item".
So what you need to do is to add a "Compose" action before the conversion to split the path and give below value:
concat('/', join(skip(split(outputs('Create_file')?['body/Path'], '/'), 2), '/'))
you can change the dynamic value of create file as per your flow.
the output path i was receiving from Create file was:
"Path": "/Shared Documents/My Library Name/My Library Folder/My file name.docx"
which was unacceptable by word online action. so after the compose action my output looks like this:
/My Library Name/My Library Folder/My file name.docx"
and with a miracle it started working.
Detailed Explanation for Advanced users:
So at my compose action what i basically did was:
concat('/', join(skip(split(outputs('Create_file')?['body/Path'], '/'), 2), '/'))
- The split function divides the file path into an array of segments using / as the delimiter
- The skip function removes the first two segments of the array. This is because the first segment is empty (due to the leading /), and the second segment is the document library name (Shared Documents), which we don’t need in the relative path.
- The join function combines the remaining segments back into a single string, with / as the separator.
- The concat function adds a leading / to the joined string to form the correct relative path:
Also i would recommend you to add a short 30 second delay before conversion, as the file sometimes takes few seconds to appear in the document library and the next action runs immediately which leads it not to find the file and give error.- StefalbertCopper Contributor
I was used your solution and indeed worked!!
Thank you so much!
- bhumikasainiCopper Contributor
I tried the suggestions by sips1 (Option 1) and evancoulson (Option 2), and both worked for me.
Adding screenshots to help anyone who stumbles upon this issue in the future.
Option 1 [using 'Name' dynamic content]:
"Location": The SharePoint site
"File": Provide the path from the "Documents" folder (or your Document Library location), until the file.
For example, if the full path is "/Shared Documents/Documents/<FolderA>/<filename.docx>", then put it as:
/FolderA/<"Name" dynamic content>
Option 2 [using 'Path' dynamic content]:
"Location": The SharePoint site
"File": replace(outputs('Save_the_file_in_SharePoint')?['body/Path'], '/Shared Documents', '')
Option 2 is less error-prone so I'd prefer that!
Hope this helps 🙂
- evancoulsonCopper Contributor
Rich Koneval
I found a solution in my case.The 'FullPath' for my word document started with "Shared Documents", given I was using a SharePoint file. This was being merged with the 'Library Name' input, which was creating the wrong location.
My solution was to remove the text "Shared Documents" from the 'FullPath' dynamic content. I used a replace function as follows;
=replace(text, oldText, newText)
=replace(outputs('Get_file_properties')?['body/{FullPath}'], 'Shared Documents', '') - Dori_kiranaCopper ContributorWant to change PDF format files to Word
- Alexander DorfmayrCopper Contributor
Hi Rich, i managed to use the "Filename wich extenson" to get the thing running on a dynamic basis....
hopefully this works for you too?
Regards
Alex
- VFXProBrass ContributorI just tried to use filename with extension and still doesn't work. This conversion is useless without a dynamic path.. and why can't it use the identifier or SharePoint ID? **bleep**, this is frustrating for such a simple process that is needed countless times in the legal community.
- sips1Copper Contributor
VFXPro I used the dynamic field "Name" in the File field and it worked.
I create a new file based upon another i.e. a template then use the Convert Word Document to PDF specifying the dynamic field "Name" of the new file to convert.
The file being converted uses quick parts and SharePoint metadata so the contents are dynamic.
Thanks,
sips1
- Jeff ZimmermanCopper Contributor
Alexander Dorfmayr I don't understand how your solution works because it still doesn't for me at all.
When I manually select the file, the inputs look like this, and it works:
{ "host": { "apiId": "subscriptions/2c8cfba1-d125-4f31-a479-50156c7ed09f/providers/Microsoft.Web/locations/westus/runtimes/unitedstates-002/apis/wordonlinebusiness", "connectionReferenceName": "shared_wordonlinebusiness", "operationId": "GetFilePDF" }, "parameters": { "source": "groups/390f8037-515b-4689-90e7-ce04092c89ab", "drive": "b!BfXatsB2n0CWjbomET8FGN5HPSqMmqVJkuANIAM7Fu6ohf774SBFQafqe7vmeMzr", "file": "01IVUUMXH5M5L7UL5P2JGYY776MHG4KCCU" } }
Note the "file": "01IVUUMXH5M5L7UL5P2JGYY776MHG4KCCU" part. Flow converts the path into that number to find the file.
But when I try to input a dynamic path (which always fails with error 400 "not found"), the input looks like this:
{ "host": { "apiId": "subscriptions/2c8cfba1-d125-4f31-a479-50156c7ed09f/providers/Microsoft.Web/locations/westus/runtimes/unitedstates-002/apis/wordonlinebusiness", "connectionReferenceName": "shared_wordonlinebusiness", "operationId": "GetFilePDF" }, "parameters": { "source": "groups/390f8037-515b-4689-90e7-ce04092c89ab", "drive": "b!BfXatsB2n0CWjbomET8FGN5HPSqMmqVJkuANIAM7Fu6ohf774SBFQafqe7vmeMzr", "file": "Shared Documents/Sarah/District Billing/CIS/2019-2020/Pre Invoices/CIS Invoice C79 19-20 IDEA PreInvoice.docx" } }
See how now there's a literal path instead of a code. Flow chokes on this.
On a lark, I put in the expression '01IVUUMXH5M5L7UL5P2JGYY776MHG4KCCU' for the "File" field and, yes, it worked again.
But the problem is that this code does not correspond to any output from Sharepoint's "Get file properties" or "Update file properties". So on my end it looks like there is still no way to use "Convert Word to PDF" dynamically.
Would it help if my document was in the root directory of the library?
- Davy LooseBrass ContributorThanks Alexander! That looks like an update because you couldn't add dynamic properties before.
- Anonymous
Same problem here. What do people do when they need to make this conversion happen automatically within a Flow? There is one third-party company out there that offers a $1,200 product but we do not need anything that sophisticated.
Since we utilize DocuSign at the end of this process, and that does the conversion, I am trying to now enable my original Word document to have the proper drop-downs, etc. before sending it through the DocuSign process.
- KeithHigginsCopper Contributor
Rich Koneval Hey Rich, did you ever figure this one out? Just stumbled across the same issue. I've tried everything I can think for dynamically creating the filename. No dice.
-Keith
- Damien_RosarioSilver Contributor
I've had the same issue testing the action.
Sadly, it's not something we can do dynamically but hoping it's a future update to the connector.
It's usefulness would skyrocket!
Cheers
Damien
- noahzaniCopper Contributor
Hi Rich Koneval
I just encountered the same problem.
from what we can see in the Flow history for a File that is selected, it looks like "/report1.docx".
i tried to recreate that dynamically with /'File name with extensions' but without success. it fails altough in the history it shows exactly the same like "/report1.docx".as long as this action does not take file inputs dynamically, it is not really useful..
- OldForestCopper Contributor
I stumbled upon the same problem this afternoon. The fact that "Convert Word Document to PDF" can't use dynamic content is ridiculous - what is the purpose of it otherwise?
- OldForestCopper ContributorThere is a workaround which makes it even sillier. If your file is stored in OneDrive for Business then its very straightforward to just use the "Convert File" action otherwise you have to use some SharePoint API shenanigans such as this guide:
http://www.cleverworkarounds.com/2018/06/30/some-seriously-powerful-and-free-pdf-functionality-in-powerapps-and-flow-part-1/
- AnonymousI'm experiencing exactly the same issue. I've even experimented hard-coding the file name in exactly how it appears when you select it through the file explorer but I get the same error when doing this. There must be some way to dynamically pass-in a file...