MicrosoftDocs / BusinessApplicationPlatform-Connectors-public

Feedback repository for Microsoft Business Application Platform Connectors documentation
Creative Commons Attribution 4.0 International
16 stars 12 forks source link

Inability to call SPROC from Azure Logic Apps - can't find syntax for the parameters #14

Closed BigBearBrian closed 4 years ago

BigBearBrian commented 4 years ago

Statement of intent:
I'm trying to automate a workflow, moving data periodically from a CSV in Sharepoint into a table in Azure SQL Database. I've gotten so far as 1) Formatting a JSON array, and 2) Creating a SPROC that successfully takes the text of the JSON Array, and imports it into the appropriate table.

Array appears like:
JSON = [{"col1":"col1Data","col2":"col2Data", ...}, <600-some more iterations>]

Invocation of stored procedure in SQL Management Studio looks like:
EXECUTE SprocName @json=N'<text of JSON above>'

===========================================
Problem:
Lack of documentation allowing me to properly format one of the following two SQL Connectors' parameters to link these two statements together:

Both Execute a Query (v2) and Execute a Stored Procedure (v2) require that parameters or query text be provided, but no indication of how said parameters should be formatted.

For example, in terms of executing a stored procedure that takes a single parameter @json, the following text "looks" correct, but results in an error:

"body": "@json=N'+@string(outputs('Convert_Rows_To_Json').body)+'"

Error: Failed to save logic app UpdateDomainCoverage. The template validation failed: 'The template action 'Execute_stored_procedure_(V2)' at line '1' and column '3148' is not valid: "The template language expression 'json=N'+@string(outputs('Convert_Rows_To_Json').body)+'' is not valid: the string character '=' at position '4' is not expected.".'.

I've tried a number of variations, for both the @json parameter on Execute Stored Procedure, or simply building the query from whole cloth in Execute SQL, to no avail. Suggestions?

bezhan-msft commented 4 years ago

The Execute a Query action takes in a SQL query, while the Execute a Stored Procedure action takes in a stored procedure.

It seems you are trying to convert data in another format to SQL/sproc using templating language which is out of scope for this documentation. For example, the error you linked throws an error due to incorrect SQL templating language. The connector and documentation assumes a valid SQL query/sproc input and thus does not provide examples as they are well defined.

BigBearBrian commented 4 years ago

So, let's go with a simple example.

I've got a json string I want to pass:

{ "oneArg": "aValue" }

If I am in SQL Server Management Studio, I would perform:

EXECUTE MySproc @json=N'{ "oneArg": "aValue" }'

I'm purely trying to get that parameter/value relationship communicated to the Connector. The initial portion of my example, "json=...", resulted in the same error, since the "=" is at the fifth ordinal location. If I put "@json=...", I got a different error, suggesting that it was trying to interpret @json as a command, in the nature of @parameters or @{...} are commands.

katwan commented 4 years ago

The sproc variable name "json" should be populated by LogicApps already under parameters drop down menu, you just need to select this parameter and input the value.

BigBearBrian commented 4 years ago

"should be populated" is correct.

I eventually got things working by manually populating:

"body": {
"json": "@{body('previousstepname').ResultSets['Table1']}"
}

In my (admittedly limited) experience working with the Logic Apps, I've not been seeing consistent results. Sometimes values like the sproc name or database name appear in the drag-in prompts. Often they don't.