Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Inserting Multiple Records In On Prem SQL Using Logic App

In last post we saw how to Insert a single Record in SQL Table which is on Prem using Logic App - Inserting data in On Premises SQL Database using Logic Apps


Here I intend to walk through the process of inserting multiple records using single Logic App, to do this we have two options we can choose from 
1. Split On 
2. For Each

So either we debatch/split the Request message and insert in table or loop through the array of records and insert in table, here I am using the later method.


Input

In earlier post we had single record  thus input was -
{
        "Description": "Edifice",
        "ID": "123",
        "Price": "3424"
    }

Here we want multiple records thus we need to create an array of records as following-
{
"Products":[
    {
        "Description": "Edifice",
        "ID": "123",
        "Price": "3424"
    },
    {
        "Description": "Edifice1",
        "ID": "1231",
        "Price": "2424"
    },
    {
        "Description": "Edifice2",
        "ID": "1232",
        "Price": "2344"
    },
    {
        "Description": "Edifice3",
        "ID": "1233",
        "Price": "2324"
    }
]
}


Now let's create Logic App 


I have covered creating instance of Logic App  in last post so will directly go to creating Logic App,first step is to add the trigger to start the LA, a HTTP endpoint 
The trigger is also supposed to accept Request message and for that there is provision to provide a schema for it (it is optional), in last post I haven't provided schema, here I intend to show the use of providing it. Click on Use Sample payload to generate schema, in the popped up editor provide the sample payload and click ok.


I’ve used the same payload as a sample message to generate the JSON schema.The JSON schema validates the incoming request and is useful for helping subsequent workflow steps know which properties to reference. Just like disassembler in BizTalk promotes properties here Trigger does that based on schema defined.


Add next action as For each, and as you can see above , Products is available as parameter to be used in For Each. Glad to see that apart from  Body(which is available to all ), Products which is an array is only available(which is valid parameter)



Select the Products and click on Add an action and add SQL connector . As am using same table used in previous post I don't have to specify connection details again rather would use same connection. 


Select Insert Row, you will see Product table gets available in dropdown list. Here if you see the properties which are valid for columns are available to choose from (Apart from Body) and this is because we have defined schema.


Assign appropriate properties against column and below is how it should look


That's it, Logic app is ready for the task




Testing


For testing I have copied the URL (which you get on Request Trigger after save) and used ARC tool to send request- data is same which I used to create schema

On checking the LA run history, trigger was successful and LA too.


If you go one level deep , you would see For Each step has four Insert Row within it(in sample four records were used) all successful(click on Next to see status of next Insert row action) 


 Finally we need to verify the entries made in DB




 As can be seen above all four records have made entry in table.



Related Post


  • Inserting data in On Premises SQL Database using Logic Apps
  • Installing and Configuring On Premises Data Gateway - By adding user to Active Directory













This post first appeared on TechFindings, please read the originial post: here

Share the post

Inserting Multiple Records In On Prem SQL Using Logic App

×

Subscribe to Techfindings

Get updates delivered right to your inbox!

Thank you for your subscription

×