K N
K N

Reputation: 343

Tabular Editor - Set "Shared Expression" value from Tabular Editor CLI (with Azure Devops)

I need to change the value of a parameter in a TOM. I am using Azure Devops with steps that include Tabular Editor CLI. I have written a one-line script that should be able to change the value of a Shared Expression. (Maybe a shared expression is read only?)

The script that will be executed

Model.Expressions["CustomerNameParameter"].Expression = "\"some value\" meta [IsParameterQuery=true, Type=\"Text\", IsParameterQueryRequired=true]";

I returns an error whenever Azure Devops tries to run it: enter image description here

It cannot find the CustomerNameParameter in the model.

My build looks like this:

Starting: Build Mode.bim from SourceDirectory
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.201.1
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents: shell
TabularEditor.exe "D:\a\1\s" -B "D:\a\1\a\Model.bim"
========================== Starting Command Output ===========================
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\ba31b528-d9a3-42cc-9099-d80d46d1ffe6.cmd""

Tabular Editor 2.12.4 (build 2.12.7563.29301)
--------------------------------
Dependency tree built in 113 ms
Loading model...
Building Model.bim file...
Finishing: Build Mode.bim from SourceDirectory

Upvotes: 3

Views: 1756

Answers (3)

Phil
Phil

Reputation: 1

My tabular model uses a shared expression (parameter) to set the connection string. The following solution worked for me. I updated the command line script in the release pipeline as follows:

echo var connectionString = Environment.GetEnvironmentVariable("SQLDWConnectionString"); >> SetConnectionStringFromEnv.cs  
echo Model.Expressions["ServerName"].Expression = "\"" + connectionString +"\"" + " meta [IsParameterQuery=true, Type=\"Text\", IsParameterQueryRequired=true]"; >> SetConnectionStringFromEnv.cs    

TabularEditor.exe "_$(Build.DefinitionName)\drop\Model.bim" -S  SetConnectionStringFromEnv.cs -D "%ASConnectionString%" "$(ASDatabaseName)"  -O -C -P -R -M -W -E -V

Upvotes: 0

OlavRab
OlavRab

Reputation: 3

What I did to fix this is create a separate script (SharedExpressions.csx) and (manually) created this line for each expression:

Model.Expressions["Start Date - Sales"].Expression = "#datetime(2019, 1, 1, 0, 0, 0) meta [IsParameterQuery=true, Type=\"DateTime\", IsParameterQueryRequired=true]";

In this case my Expressions are datetime, but you can change it to anything you like. Just be very aware with the quote placement.

Then in my pipeline I use the following script to execute the changes:

start /wait TabularEditor.exe "$(System.DefaultWorkingDirectory)/Tabular Model/model/model.bim" -S "$(System.DefaultWorkingDirectory)/Tabular Model/scripts/SharedExpressions.csx" -D -V

Upvotes: 0

Dan
Dan

Reputation: 10680

Your script looks good. Have you tried executing it within the Tabular Editor UI?

enter image description here

Perhaps the parameter is named differently in your model. You can use the following script in the CLI to output the list of parameters:

foreach(var expr in Model.Expressions) Info(expr.Name);

The result when executed in the CLI on the model shown in the screenshot above:

enter image description here

Upvotes: 2

Related Questions