How to run multiple XMLA statements in the same script

Steen Schlüter Persson 21 Reputation points
2021-04-09T10:56:41.577+00:00

Hi,

I'm working on a script to create around 50 roles for a Tabular Model, but have to troubles figuring out how I can run them all at once.

The script looks like below, just only with 2 roles as an example -

{
"createOrReplace": {
"object": {
"database": "Test",
"role": "Group A"
},
"role": {
"name": "Group A",
"modelPermission": "read",
"members": [
{
"memberName": "Domain\\xxx",
"memberId": "S-......-73405"
}
],
"tablePermissions": [
{
"name": "Tablename",
"filterExpression": "'TableName'[HomeDepartment] IN ({\"XX\",\"YY\"}) && 'TableName'[HomeUnit] IN ({\"ZZ\",\"WW\"})"
}
]
}
}
}

// Group B

"createOrReplace": {
"object": {
"database": "Test",
"role": "Group B"
},
"role": {
"name": "Group B",
"modelPermission": "read",
"members": [
{
"memberName": "Domain\GGG",
"memberId": "S.......-53912"
},
{
"memberName": "Domain\AAA",
"memberId": "S......-26483"
}
],
"tablePermissions": [
{
"name": "TableName",
"filterExpression": "'TableName'[HomeDepartment] IN ({\"HH\",\"KK\",\"TT\",\"FF\",\"MM\"}) && 'TableName'[HomeUnit] IN ({\"EE\"})"
}
]
}
}

I can run each "createOrReplace" section individually and it works fine and create the roles with permissions with out any problems but if I try to run the whole script (hit F5 in SSMS) I get the error -
Executing the query ...
The JSON DDL request failed with the following error: Additional text encountered after finished reading JSON content: {. Path '', line 30, position 1..
Run complete

I have then tried to add <Batch Transaction="true" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> ..... </Batch> around the script, but then I get the error - The { text node at line 9, column 3 cannot appear inside the Batch element (namespace http://schemas.microsoft.com/analysisservices/2003/engine) under Envelope/Body/Execute/Command. This element can only have text nodes containing white-space characters.

I have also tried other combinations/suggestions, but none of them works.

My experience running XMLA scripts are fairly limited, so I hope some one can help on how I can fix this? I can of course always just run each individual step to get the roles created/updated but it would be nice just to be able to execute the whole script at once.

Regards
Steen

SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Darren Gosbell 1,471 Reputation points
    2021-04-12T00:31:15.567+00:00

    I think you might need to use the sequence command to run multiple operations in the one batch


1 additional answer

Sort by: Most helpful
  1. Lukas Yu -MSFT 5,826 Reputation points
    2021-04-13T08:52:03.223+00:00

    Glad you have resolve the issue, if you have further issue, feel free to post in the forum.

    0 comments No comments

Your answer

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