296 viewsScriptingsubroutines

Dear Quantrix Answers team,

As I understand it, there are two options when writing scripts: default and “Expert Mode.” Based on what I have uncovered, when you use the “default mode,” you are already writing code inside the “void perform()” function.  This poses a problem when using subroutines, as you cannot usually add a subroutine inside a function.  Please correct me if I am wrong in this case, as I am not well-versed in Groovy.

Now, I have three other questions and a request for review:

  • I closed the “void perform()” function and added a subroutine outside it (see below in bold).  I have tested all components separately using the Scripting Console.  Will this work?
  • Why does the “BuildArchive()” subroutine I created disappear when I unselect “Expert Mode?” Does this mean the default mode scripting window only shows you the “void perform ()” function?
  • Why do we need the “Boolean enabled()” function?  What does it do?
  • Please see the code below and advise if you see potential improvements.

I must ensure we have an NDA in place to provide the model.  Until then, please let me know if the code below will suffice.

Thank you very much!

All the best, Andrés


void perform()


alert(“Did you create a new version in the Archive matrices and select that version in the Model Set Up Matrix?”)

def Version = |Model Set Up::Version to Archive|.value

alert(“The archive you will write is: ” + Version)

// Check if the selected archive has data, and if so, verify whether to overwrite it or not

def test_value = |Archive Control|.getSelection(Version).value

if (test_value > 0) {

def String MoveOn = ask(“Are you sure you want to overwrite the” + Version +” archive?”, [“Yes/No “:String], [“Yes/No “: “Yes”])

switch (MoveOn) {

case “[Yes/No:Yes]”:

BuildArchive () // Replace the archives


case “[Yes/No:No]”: // Exit


default: //Exit with error message

alert(“This is not a valid option.  Please try again.”)



} else if (test_value = 0) {

BuildArchive () // Create the archive in a new version



// Update and archive each scenario into the selected Version

def BuildArchive () {

def String ScenarioBuilder = “”

for (def int count_tracker in 0..<3) {

switch (count_tracker) {

case 0:

ScenarioBuilder = “Downside”


case 1:

ScenarioBuilder = “Upside”


case 2:

ScenarioBuilder = “Base”



// Shawn’s Example :  |’Archived – Monthly’|.getSelection(Version).values = |Finance Monthly|.values

|Dx Rate Scenario Selector::Stage 1:Dx Rate|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Dx Rate:Final|.getSelection(ScenarioBuilder).values

|Dx Rate Scenario Selector::Eligibility:Stage 1|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Eligibility Rate:Final:Downside|.getSelection(ScenarioBuilder).values

|Dx Rate Scenario Selector::Eligibility 2:Stage 1|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Eligibility 2 Rate:Final:Downside|.getSelection(ScenarioBuilder).values

|Dx Rate Scenario Selector::Eligibility 3:Stage 1|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Eligibility 3 Rate:Final:Downside|.getSelection(ScenarioBuilder).values

|Competitive Impact Selector::Competitive Impact|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Competitive Impact:Final:Downside|.getSelection(ScenarioBuilder).values

|Conversion Rates Scenarios Selection::Enrollment to PA:Conversion Time:Initial|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Enrollment to PA Conversion:Final:Downside|.getSelection(ScenarioBuilder).values

|Conversion Rates Scenarios Selection::PA to NPS:Conversion Time:Initial|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::PA to NPS Conversion:Final:Downside|.getSelection(ScenarioBuilder).values

|Clinical Conversion Rates Selector::Conversion Rates|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Clinical Conversions:Final:Downside|.getSelection(ScenarioBuilder).values

|Enrollment Rate Scenario Selection::Initial Enrollment Rate:Stage 1|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Market Penetration:Final:Downside|.getSelection(ScenarioBuilder).values

|Compliance Scenario Selector::Year 1 Compliance|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Compliance:Final:Downside|.getSelection(ScenarioBuilder).values

|Persistence Scenario Selector::Persistence|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Persistence:Final:Downside|.getSelection(ScenarioBuilder).values

|% Free Drug Scenario Selector::% Free Drug|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Free Drug:Final:Downside|.getSelection(ScenarioBuilder).values

|Dose Split Scenario Selector::Starter SKU 1|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Dose Split:Final:Downside|.getSelection(ScenarioBuilder).values

|Price Scenario Selector::Price per Bottle|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Price:Final:Downside|.getSelection(ScenarioBuilder).values

|Intent to Treat Selector::Very High|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Intent to Treat:Final:Downside|.getSelection(ScenarioBuilder).values

|’In the Field Selector’::’In the Field’|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::’Launch Date’:Final:Downside|.getSelection(ScenarioBuilder).values

|Diagnosis Adj Scenarios Selection::Diagnosis Adjustment|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Diagnosis Adjustment:Final:Downside|.getSelection(ScenarioBuilder).values

|% Neurology Selector::|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::% Neurology:Final:Downside|.getSelection(ScenarioBuilder).values

|Prescription Rate Scenario Selection|.getSelection(ScenarioBuilder).values = |Saved Scenarios Selector::Prescription Rate:Final:Downside|.getSelection(ScenarioBuilder).values

// |Therapy Launch Scenarios::Pediatric Label|.getSelection(ScenarioBuilder).values = |Pediatric Label Selector::Pediatric Label:Final:Downside|.getSelection(ScenarioBuilder).values


pause (1)

//UPDATE Archive Tables

// Patients Folder

|’Archived – Patient Funnel Weekly Scenarios’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Patient Funnel Weekly Scenarios|.getSelection(ScenarioBuilder).values

|’Archived – Patient Funnel Annual Scenarios’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Patient Funnel Annual Scenarios|.getSelection(ScenarioBuilder).values

// Finance Folder

|’Archived – Finance Weekly’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Finance Weekly|.getSelection(ScenarioBuilder).values

|’Archived – Finance Monthly’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Finance Monthly|.getSelection(ScenarioBuilder).values

|’Archived – Finance Weekly Scenarios’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Finance Weekly Scenarios|.getSelection(ScenarioBuilder).values

|’Archived – Finance Monthly Scenarios’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Finance Monthly Scenarios|.getSelection(ScenarioBuilder).values

// Revenue Folder

|’Archived GTN & Revenue Monthly’|.getSelection(ScenarioBuilder).getSelection(Version).values = |’GTN & Revenue Monthly’|.getSelection(ScenarioBuilder).values

// Launch Folder

|’Archived – Launch Forecast’|.getSelection(ScenarioBuilder).getSelection(Version).values = |Launch Forecast|.getSelection(ScenarioBuilder).values

|’Archived – KeyAssumptions’|.getSelection(ScenarioBuilder).getSelection(Version).values = |KeyAssumptions|.getSelection(ScenarioBuilder).values

|’Archived – KeyAssumptionsWeekly’|.getSelection(ScenarioBuilder).getSelection(Version).values = |KeyAssumptionsWeekly|.getSelection(ScenarioBuilder).values



boolean enabled()


return true;


Gilbert Answered question November 14, 2023

Hi Andrés,

Did you watch the Dimension conference today? Ben Wake answered all these questions about the Expert mode to a user questions which was probably yours … Ifnot, you might want to see the recording of this?

Concerning your example, I looks to me that you need more than one script to solve this.

But … maybe I do understand your application wrong. I looks like very Excel – e.g. building one model and then exchanging the numbers by script.

Or, as Quantrix is multidimensional, you would do this just as adding a category “Scenario” to your matrices. This will solve all what you want to do without any scripts. If you do not understand what I mean, just make a very simple example model, and explain what you want to do, and then I can show you how to do this for several scenarios …

Good luck, Gilles

Gilbert Answered question November 14, 2023
You are viewing 1 out of 1 answers, click here to view all answers.

Latest Questions

Wrap text in scripted buttons? 1 Answer | 0 Votes
Claculate product 2 Answers | 0 Votes
Sum by group in the same matrix 4 Answers | 0 Votes
Constrain input – varchar 1 Answer | 0 Votes