Dynamic function execution in Logic App

JK 1 Reputation point
2021-08-10T15:26:51.483+00:00

Hello all,

I'm trying to simplify logical paths in a logic app, and being able to dynamically execute functions that are sourced externally (in my case, a CosmosDb). In an attempt to prove the concept out, I've used a simple date conversion function that resides in my CosmosDb.

So far I've tried putting curly braces on the content in Cosmos, and an @ sign, but have yet to find success. Could someone please elaborate on the proper way to perform this kind of action -> executing dynamic functions in a Logic App.

Kind Regards,

Jon

Compose Task Code:

        "Compose": {  
            "inputs": {  
                "Value": "@{body('LookupProcessConfig')?['value'][0].Function}"  
            },  
            "runAfter": {  
                "LookupProcessConfig": [  
                    "Succeeded"  
                ]  
            },  
            "type": "Compose"  

Cosmos Doc:

{

"ProcessName": "Dynamic FunctionTest",  
"Executable": "laDynamicFunctionTest",  
"ExecutableType": "Azure Logic App",  
"IsActive": true,  
"Version": 0,  
"Function": "convertFromUtc(utcNow(),'US Eastern Standard Time','yyyyMMddHHmmssfff')",  
"_shardkey": "laDynamicFunctionTest"  

}

121976-dynamiclogicappfunction.png

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Samara Soucy - MSFT 5,141 Reputation points
    2021-08-12T18:06:14.617+00:00

    Logic Apps do not allow parsing expressions at runtime, but there are options for doing something like this without complicating your workflow.

    If you are on the new Logic Apps standard plan, then you get access to the Execute JavaScript action which is still in preview. While Logic Apps doesn't allow you to evaluate code dynamically, JavaScript does.

    I added a Parse JSON action to my version just to make the expression a little simpler, but basically the code boils down to return eval(<string retrieved from cosmos>)

    122844-2021-08-12-14-01-58-test-microsoft-azure.png

    The second option would be essentially the same but leveraging Azure Functions. It's quite a bit more cumbersome, but it works on the Logic Apps consumption plan and you have more language options if you don't want to utilize JavaScript.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.