I am using a dialogue box to select the primary and secondary tables but when the JMP query builder runs it fails to substitute the file path names correctly, even if I manually resolve this the next time the script needs to reference the tables it falls over
Error: Name Unresolved: PRIMARYNAME in access or evaluation of 'PRIMARYNAME' , PRIMARYNAME/*###*/
// Step 1: Get names of all open data tables
dtNames = {};
For(t = 1, t <= N Table(), t++,
Insert Into(dtNames, Data Table(t) << Get Name)
);
// Step 2: Dialog to select two tables
nw2 = New Window("Data Table Selector - Note both data tables must be open in this JMP session",
<<Modal(),
V List Box(
Text Box("Select Primary Table (with TS):"),
lb1 = List Box(dtNames, width(600), nlines(8), MaxItems(1)),
Spacer Box(Size(10, 10)),
Text Box("Select Secondary Table (with START/END TIME):"),
lb2 = List Box(dtNames, width(600), nlines(8), MaxItems(1)),
Spacer Box(Size(10, 10)),
H List Box(
Button Box("OK",
primaryTableName = lb1 << Get Selected;
secondaryTableName = lb2 << Get Selected;
If(Is Missing(primaryTableName) | Is Missing(secondaryTableName),
New Window("Error", <<Modal(), Text Box("Please select both tables."));
Stop();
);
If(primaryTableName == secondaryTableName,
New Window("Error",
<<Modal(),
Text Box("Please select two different tables.")
);
Stop();
);
// Close dialog
Window(
"Data Table Selector - Note both data tables must be open in this JMP session"
) << Close Window;
),
Button Box("Cancel",
Window(
"Data Table Selector - Note both data tables must be open in this JMP session"
) << Close Window
)
)
)
);
// Step 3: Get references and file paths
dtPrimary = Data Table(primaryTableName[1]);
dtSecondary = Data Table(secondaryTableName[1]);
primaryPath = dtPrimary << Get Path;
secondaryPath = dtSecondary << Get Path;
// Check if tables are saved
If(Is Missing(primaryPath) | Is Missing(secondaryPath),
New Window("Error",
<<Modal(),
Text Box("Both tables must be saved JMP files. Please save and try again.")
);
Throw("Both tables must be saved JMP files. Please save and try again.");
);
// Step 4: Get all column names from both tables
primaryCols = dtPrimary << Get Column Names("String");
secondaryCols = dtSecondary << Get Column Names("String");
// Step 5: Build Select() clause for all columns
selectExprList = {};
For(i = 1, i <= N Items(primaryCols), i++,
Insert Into(selectExprList, Expr(Column(COLNAME, t1)))
);
For(i = 1, i <= N Items(secondaryCols), i++,
Insert Into(selectExprList, Expr(Column(COLNAME, t2)))
);
// Substitute actual column names into Select() expressions
For(i = 1, i <= N Items(primaryCols), i++,
selectExprList[i] = Substitute(selectExprList[i], Expr(COLNAME), primaryCols[i])
);
For(i = 1, i <= N Items(secondaryCols), i++,
selectExprList[N Items(primaryCols) + i] = Substitute(
selectExprList[N Items(primaryCols) + i],
Expr(COLNAME), secondaryCols[i]
)
);
// Step 6: Build the SQL Query using unquoted Expr tokens for substitution
sqlExpr = Expr(
New SQL Query(
Version(130),
Connection("JMP"),
JMP Tables(["PRIMARYNAME" => "PRIMARYPATH", "SECONDARYNAME" => "SECONDARYPATH"]),
QueryName(PRIMARYNAME || " join " || SECONDARYNAME),
Select(__SELECTALLCOLUMNS__),
From(
Table(PRIMARYNAME, Alias("t1")),
Table(
SECONDARYNAME,
Alias("t2"),
Join(
Type(Left Outer),
LE(Column("TS", "t1"), Column("END TIME", "t2")) &
GE(Column("TS", "t1"), Column("START TIME", "t2"))
)
)
)
) << Modify
);
// Step 7: Substitute table names, paths, and all columns
sqlExpr = Substitute(sqlExpr,
"PRIMARYNAME", primaryTableName[1],
"PRIMARYPATH", primaryPath,
"SECONDARYNAME", secondaryTableName[1],
"SECONDARYPATH", secondaryPath,
Expr(__SELECTALLCOLUMNS__), Expr(selectExprList)
);
// Debug: Show the final SQL Query code (optional, for troubleshooting)
Write(Expr(sqlExpr));
// Step 8: Run the query
Eval(sqlExpr);
Edit (jthi): added JSL formatting