jeffhollan / LogicAppTemplateCreator

Script to convert Logic Apps into templates for deployment
MIT License
143 stars 74 forks source link

Hardcoded values for organization for CDS connectors of type dynamicscrmonline #104

Open dhrumeshgandhi opened 3 years ago

dhrumeshgandhi commented 3 years ago

We are facing issue with exporting template of Logic app which contains older dynamicscrmonline typed connectors. We have action as shown in below:

"Create_error_log": {
    "inputs": {
        "body": {
            <Some Parameters>
        },
        "host": {
            "connection": {
                "name": "@parameters('$connections')['dynamicscrmonline']['connectionId']"
            }
        },
        "method": "post",
        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('orgxxxxxxx.crm4'))}/tables/@{encodeURIComponent(encodeURIComponent('accounts'))}/items"
    },
    "runAfter": {
        "Scope": [
            "Failed",
            "Skipped",
            "TimedOut"
        ]
    },
    "type": "ApiConnection"
}

When we export template from this using Get-LogicAppTemplate cmdlet, it is exported as is and no parameters are exported. We want to make CE organization ("orgxxxxxxx.crm4") to be replaced with parameter. Please let me know if any more information is required.

dhrumeshgandhi commented 3 years ago

We are also facing this issue with the CDS connectors of type commondataservice if there not v2.

Found the issue: there is no switch case for dynamicscrmonline type of connector in handleActions method (for both actions and triggers) of TemplateGenerator.cs and also there is static code to fetch dataset from path, which doesn't work when the connector is not v2 for actions or not v1 for triggers.

Solution that i found: Add a fall through case for "dynamicscrmonline" connector to the commondataservice case and update the logic to select dataset name to dynamic from static. Following code works for dynamic selection:

var dataset = "";
var datasetIndex = Array.FindIndex(pathsubsets, pathsubset => pathsubset == "datasets") + 1;
if (datasetIndex < pathsubsets.Length)
{
      dataset = pathsubsets[datasetIndex];
}

Gist for updated TemplateGenerator.cs

Please go through the change and correct if feasible.

Thanks in advance.

dhrumeshgandhi commented 3 years ago

We are also facing this issue with the CDS connectors of type commondataservice if it is not v2.

Found the issue: there is no switch case for dynamicscrmonline type of connector in handleActions method (for both actions and triggers) of TemplateGenerator.cs and also there is static code to fetch dataset from path, which doesn't work when the connector is not v2 for actions or not v1 for triggers.

Solution that i found: Add a fall-through case for "dynamicscrmonline" connector to the commondataservice case and update the logic to select dataset name to dynamic from static. The following code works for dynamic selection:

var dataset = "";
var datasetIndex = Array.FindIndex(pathsubsets, pathsubset => pathsubset == "datasets") + 1;
if (datasetIndex < pathsubsets.Length)
{
      dataset = pathsubsets[datasetIndex];
}

Gist for updated TemplateGenerator.cs

Please go through the change and correct if feasible.

Thanks in advance.

Can anyone help us with this? @MLogdberg @jeffhollan

MLogdberg commented 3 years ago

Sorry for late response, totaly fell out of scope. I'll take a look at this, solution looks good at a first glance.

dhrumeshgandhi commented 3 years ago

@MLogdberg, Thanks for replying.

And can you please confirm if support for azure function action will be added or not?

MLogdberg commented 3 years ago

Should be solved via #111 What is the functions support you are refering to? @dhrumeshgandhi

dhrumeshgandhi commented 3 years ago

Should be solved via #111 What is the functions support you are refering to? @dhrumeshgandhi

We are using Azure functions in our logic apps, which are not parameterized while using LogicAppTemplateCreator.

MLogdberg commented 3 years ago

Yea I use it alot aswell, when I do extractions it's parameterized as follow, are you missing anything there?

"INT119A-CreateQuoteD365": { "runAfter": {}, "type": "Function", "inputs": { "body": "@outputs('Compose_body')", "function": { "id": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',parameters('INT119A-CreateQuoteD365-ResourceGroup'),'/providers/Microsoft.Web/sites/',parameters('INT119A-CreateQuoteD365-FunctionApp'),'/functions/',parameters('INT119A-CreateQuoteD365-FunctionName'))]" } } } },

dhrumeshgandhi commented 3 years ago

Is this the same DLL that we get when we install the module from PS Gallery using Install-Module -Name LogicAppTemplate? Because when we tried to parameterize the azure function it didn't work so instead we switched to HTTP action to call the Azure function.