cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sven_Rahn
Regular Visitor

Power Platform Build Tools: Connection reference

Hi!

So we successfully implemented ALM with some Azure DevOps Pipelines and the official Power Platform Build Tools. But there's one problem:

When importing a solution which contains a Flow and its connection reference, it doesn't update itself correctly and just turns itself off.
It is as if I would import the solution with the old solution explorer UI. The new PowerApps solution UI asks when importing to update the connection references. But the old UI and the Power Platform Build Tools in Azure DevOps just disable the Flow.

So after having everything automated, we still have to go into the prod environment and update each connection reference and activate each Flow (even if it didn't change). I guess the process is worse now than without ALM.

Are there any workarounds or possibilities to use the "new UI" import API? Or am I missing something? How should this be handled with ALM?

14 REPLIES 14

Hi @ryanspain ,

 

I just don't see what could be wrong compared to the example you gave above.  One issue I thought about is perhaps because I'm trying to modify a Managed Solution. 

 

 

$tenantId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
$appId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
$appSecret = "xxxxxxxxx.xxxxxxx.xxx.xxxxxxxxxx"
$serviceUrl = "https://xxxxxxxxxx.crmX.dynamics.com/"

<# Get Access Token #>
$authContextUrl = "https://login.microsoftonline.com/$tenantId"
$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($authContextUrl)
$credential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential($appId, $appSecret)
$authResult = $authContext.AcquireToken($serviceUrl, $credential)

<# Set Headers #>
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("CallerObjectId", "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx")
$headers.Add("Authorization", "Bearer " + $authResult.AccessToken )
$headers.Add("Content-Type", "application/json")

<# Set Body #>
$body = "{ 'statecode': 1, 'statuscode': 2 }"


<# Run Request #>
try {
	$response = Invoke-WebRequest -Uri 'https://xxxxxxxxxx.crmX.dynamics.com/api/data/v9.2/workflows(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX)' -Method 'PATCH' -Headers $headers -Body $body
	exit 0
}catch{	
	"Status Code: $($_.Exception.Response.StatusCode.value__)"
	"Exception Message: $($_.Exception.Message)"
	exit 1
}
$response.StatusCode
$response.StatusDescription

 

I've tried your code and it works for me @ScottCostello.

 

I even tried activating a cloud flow within a managed solution but that worked as expected too.

 

Could you try adding the below to your catch statement to try and extract the error message?

$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd()
"Response Body:  $($responseBody)"

 

The response should be something like the below:

ryanspain_0-1630603712401.png

 

 

This is the error message I get @ryanspain 

 

{
   "error":{
      "code":"0x0",
      "message":"An error occurred while validating input parameters: System.ArgumentException: Stream was not readable.\r\n   at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)\r\n   at System.IO.StreamReader..ctor(Stream stream, Encoding encoding)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightInputContext.CreateTextReader(Stream messageStream, Encoding encoding)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightInputContext..ctor(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n   at Microsoft.OData.Json.ODataJsonFormat.CreateInputContext(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n   at Microsoft.OData.ODataMessageReader.ReadFromInput[T](Func`2 readFunc, ODataPayloadKind[] payloadKinds)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"
   }
}

@ScottCostello, unfortunately that error message doesn't provide us with much other than there is a problem with the inputs.

 

Could you try changing the body statement in PowerShell to match the below? This is a long shot!

 

 

$body = "{
`n    `"statecode`": 1,
`n    `"statuscode`": 2
`n}"

 

 

Also, what version of PowerShell is this executing on? i.e. run Get-Host | Select-Object Version.

_raphael
New Member

@ryanspain 

how can I get the correct authority URL?

$authContextUrl="https://login.microsoftonline.com/$tenantId"

gives me the following error:

New-Object : Cannot find type [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]: verify that the
assembly containing this type is loaded.

 

thanks for your help.

 

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.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (4,548)