Search code examples
htmlazureazure-logic-apps

How to customise 'Create HTML table' activity in Logic App?


I have a requirement to display a table in mail. I have used 'Create HTML Table' activity in logic app and below is the result.

enter image description here

I want to add colors to alternative rows. Something like below.

enter image description here

Is there a way to customise the 'Create HTML table' activity in Logic app to increase the table size and add colors?


Solution

  • You can do this using Logic apps. Use the following steps in the work flow :

    1. Receive the http request.
    2. Initialize the output as array with initial value of [].
    3. Initialize the sequence variable as integer.
    4. Enter in to a for loop.
    5. In the for loop, increment the sequence
    6. After incrementing, append to output array the value addProperty(items('For_each'),'S.No',variables('Sequence')) What this does is add the S.No property to each JSON and append it to the new output array variable.

    Make sure you set the parallelism concurrency in the foreach loop to 1 so it runs sequentially else you will have weird sequence counts. enter image description here

    Your workflow will look like this.

    enter image description here

    The code version looks like this.

    {
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Create_HTML_table": {
                "inputs": {
                    "format": "HTML",
                    "from": "@variables('output')"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Table"
            },
            "For_each": {
                "actions": {
                    "Append_to_output_array": {
                        "inputs": {
                            "name": "output",
                            "value": "@addProperty(items('For_each'),'Sequence',variables('Sequence'))"
                        },
                        "runAfter": {
                            "Increment_Sequence": [
                                "Succeeded"
                            ]
                        },
                        "type": "AppendToArrayVariable"
                    },
                    "Increment_Sequence": {
                        "inputs": {
                            "name": "Sequence",
                            "value": 1
                        },
                        "runAfter": {},
                        "type": "IncrementVariable"
                    }
                },
                "foreach": "@triggerBody()",
                "runAfter": {
                    "Initialize_Sequence": [
                        "Succeeded"
                    ]
                },
                "runtimeConfiguration": {
                    "concurrency": {
                        "repetitions": 1
                    }
                },
                "type": "Foreach"
            },
            "Initialize_Sequence": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Sequence",
                            "type": "integer",
                            "value": 0
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_output": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_output": {
                "inputs": {
                    "variables": [
                        {
                            "name": "output",
                            "type": "array",
                            "value": []
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {
                        "items": {
                            "properties": {
                                "File": {
                                    "type": "string"
                                },
                                "File availability": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "File",
                                "File availability"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
    }