PowerApps

Sometimes when we are working with PowerApps, adding new connections like to Microsoft Flow or external services and then we decide we don’t need some of them anymore and therefore we are removing it, but forgetting to first delete it in PowerApps, we are finding ourselves in situation, where when trying to export the app as a package, we are facing a very hard to debug issue.

When such situation can occur?

Imagine, you have a button that when clicked triggers Flow. Or is sending e-mail through Office365 Outlook connector. While working with the app you realizes, that the Flow is wrong, or the connector uses wrong credentials. So you are deleting the Flow or connector.

Next you realize, that the button in your PowerApp causes an error, because it is bond to a non-existing Flow/ Connector. So you simply remove that code from button’s “onclick” or replace it with something else, or… remove a button from the app instead of FIRST removing that related Flow/ Connection from the app, by clicking the Button, then “Action->Flows” and then from the associated list – “Remove from app”, like below:

Removing Flow connection from the PowerApps button
Removing Flow connection from the PowerApps button

Then you publish the app and… forget about that situation. Versions later you want to export it, but instead you only see a red bar (red!!!) showing: “Could not find flow ‘GUID’.” or “Could not find connection ‘GUID’.”:

Error exporting PowerApps as a package
Error exporting PowerApps as a package

Why export fails?

The reason why the issue appears is that export mechanism is trying to get all the Connections it has defined in app so therefore when importing the app later user is going to be able to define them and provide credentials. Since that particular connection doesn’t exist (as it was deleted), but there is still a reference to it from the application, export mechanism cannot find it, access it details and therefore to complete it’s execution.

How to debug?

There wouldn’t be nothing bad about the issue, if not the fact, that as a reason we are only given a GUID of the missing connection, not it’s name or any other information that could help us to debug.

Nevertheless even if we knew what was missing, I don’t know any way to restore that missing connection preserving it’s GUID.

Meanwhile, to find out what is missing, the simplest way is to do the following (I am using Visual Studio Code for that purpose):

  1. Save your app locally, on your computer,
  2. Change file extension from *.msapp to *.zip,
  3. DO NOT UNZIP! Just open using 7zip app for example,
  4. Open file: {zip}\References\DataSources.json,
  5. Search for the displayed GUID,
  6. Press “F1” and type “Format Document” to get a nice looking JSON formatted file,
  7. Search the “Name” property inside the object that matches the GUID in the “AddinConnectorId” property.
Missing connection for a given GUID
Missing connection for a given GUID

So this is the name of the connection you are missing. Any bell rings in your head? I guess it should, as that is the only information you can find about it.

How to fix it?

If the button related to the issue is still inside your app and hopefully not replaced by anything else, or you know in which version the change was made and it is not tens of them before, you can simply click the button, then “Action->Flows” and then select to “Remove from app”:

Removing Flow connection from the PowerApps button
Removing Flow connection from the PowerApps button

Then publish new version and try again. Issue should be solved.

What if I cannot do it the easy way?

Additionally open “View” -> “Data sources” and find the not connected Flow there. Then simply remove it and again, save and publish app:

Removing missing connection from PowerApps
Removing missing connection from PowerApps

What if there is no missing connection in Data sources?

The only solution I found so far is to work on the files inside the saved locally *.msapp file. There are basically two files that usually matches the displayed GUID:

Files containing searched GUID
Files containing searched GUID
  • Properties.json – file located in a root of the msapp file,
  • DataSources.json – file located in “References” subfolder.

To begin fixes first go through the below steps:

  • Save your app locally, on your computer:
Save PowerApps locally on your computer
Save PowerApps locally on your computer
  • Change file extension from *.msapp to *.zip,
  • DO NOT UNZIP! Just open using 7zip app for example,
  • Copy the two files mentioned above outside the ZIP file.

Now you’re ready to go fixing 🙂

DataSources.json

Steps then are as following (again, using Visual Studio Code):

  • Open DataSources.json,
  • Click “F1” and “Format Document” to get a readable JSON file,
  • Search for the GUID,
  • Once found, select all object that is containing it and remove it,
Finding the missing GUID in DataSources.json file
Finding the missing GUID in DataSources.json file
  • Click “CTRL+A” to select all code of the file,
  • Again click “F1” and type “Join Lines” to again put the code in a single line.
Joining code lines into a single one in Visual Studio Code
Joining code lines into a single one in Visual Studio Code

Finally move the file back to the ZIP file, to overwrite the existing file. Done!

Properties.json

That is the second file that should be fixed. It’s a bit more complex to make this one work. Steps here are as following (using Visual Studio Code):

  • Open Properties.json,
  • Click “F1” and “Format Document” to get a readable JSON file
  • Search for the GUID,
  • It should be found inside an escaped JSON code being a value of the “LocalConnectionReferences” attribute,
  • Copy it’s value, but without opening and closing quote,
  • Paste copied text in new file,
  • Change document type to JSON,
Change document type to JSON in Visual Studio Code
Change document type to JSON in Visual Studio Code
  • Replace escaped quotes with quotes (\\" to ") to get valid JSON,
Replace escaped quotes with not escaped
Replace escaped quotes with not escaped
  • Press “F1” and “Format Document” to get a nice looking JSON structure,
  • Remove the whole block containing missing GUID,
  • “CTRL+A” to select all code,
  • Again press “F1” and type “Join Lines” to get code back to single line,
  • Again escape " replacing ” with \\",
  • Copy the code and replace the value of the “LocalConnectionReferences” attribute inside the “Properties.json” file.

Finally move the file back to the ZIP file, to overwrite the existing file. Done!

Uploading fixed file

Last step is to change back the extension of a file from *.zip to *.msapp. After doing that you’re ready to go.

Now is the time to open the new app in PowerApps designer. To do that go to the https://us.create.powerapps.com/studio/ url.

There click “Open” and “Browse” and navigate to the msapp file you would like to open:

Opening local msapp file in PowerApps
Opening local msapp file in PowerApps

After that simply wait until app is loaded. Once it is loaded, you will unfortunately need to re-configure all connection and fix issues. Finally save it as a new one (or overwrite the existing one) and then try to export it as package again. Works like a charm! 🙂

If you have any questions or comments please live them below!