cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
RobRobeyns
Level III

How to extract a report name in a generic way using jsl

Hi,

 

I would like to extract the report name using jsl. The script posted below is able to do so, but not for all types of reports. For example: I am able to extract the correct report name for a Graphbuilder report, but not for a Fit Manova report.

This results in an error: "Name Unresolved: rescript in access or evaluation of 'repscript', repscript/*###*/"

 

Is there a solution to make this script more generic/robust, so that it would work for all types of reports?

 

Names Default To Here(1);
dt=Current Data Table();
rep=Current Report();


//data table name
dtname=dt<<Get Name();
//Report title, Scriptable Object, and finally script of report in Char form
reptitle=rep<<get window title;
substitute into(reptitle,Eval(dtname)||" - ","");
//capture first word of reptitle
reptitlefw= word(1,reptitle," ");

report_type=reptitlefw||" ?";

//Eval(Parse(Eval Insert("repSO=rep[^(report_type)^]<<get scriptable object;")));

Try(Eval(Eval Expr(repSO=rep[Expr(report_type)]<<Get Scriptable Object));


repscript=Char(repSO<<get script));


//get array of row states
rowstates=dt<<get row states;

//script that sets row states to values in array
rowstatescript=Eval Insert(
"Names Default To Here(1);
dt=Current Data Table();

rowstates=^Char(rowstates)^;

for(i=1,i<=NRows(dt),i++,
Row State(dt,i)=As Row State(rowstates[i]);
);");


//save script for row states and report to data table
eval(parse("dt<<new script(reptitle,"||rowstatescript||repscript||")"));

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to extract a report name in a generic way using jsl

The issue with the JSL you have been using, is that not all window titles provide the correct information to get the Scriptable Object that can retrieve the Script.  I have found that using the initial Outline Box() from within the window is a more robust method.  However, it still will not work in all cases.  If a BY() group is specified, it will return the script for only the first BY() group.  Here is my modification to the code

Names Default To Here(1);
dt=Current Data Table();
rep=Current Report();


//data table name
dtname=dt<<Get Name();
//Report title, Scriptable Object, and finally script of report in Char form
reptitle=rep<<get window title;

// The Get Scriptable Object is a message available to the Report's
// initial Outline Box

repSO = window(reptitle)[outlinebox(1)]<<get Scriptable Object;

repscript=Char(repSO<<get script);

//get array of row states
rowstates=dt<<get row states;

//script that sets row states to values in array
rowstatescript=Eval Insert(
"Names Default To Here(1);
dt=Current Data Table();

rowstates=^Char(rowstates)^;

for(i=1,i<=NRows(dt),i++,
Row State(dt,i)=As Row State(rowstates[i]);
);");


//save script for row states and report to data table
eval(parse("dt<<new script(reptitle,"||rowstatescript||repscript||")"));
Jim

View solution in original post

3 REPLIES 3

Re: How to extract a report name in a generic way using jsl

Hi,

I modified your script a bit so that it now gets the scriptable object from OutlineBox(1) of the current report, rather than trying to use the report name (see below).  Please try it out and let me know if it works for you.

 

Names Default To Here(1);
dt=Current Data Table();
rep=Current Report();

repSo=rep[OutlineBox(1)]<<Get Scriptable Object;
repscript=Char(repSO<<get script);

//data table name
dtname=dt<<Get Name();
//Report title, Scriptable Object, and finally script of report in Char form
reptitle=rep<<get window title;
substitute into(reptitle,Eval(dtname)||" - ","");

//get array of row states
rowstates=dt<<get row states;

//script that sets row states to values in array
rowstatescript=Eval Insert(
"Names Default To Here(1);
dt=Current Data Table();

rowstates=^Char(rowstates)^;

for(i=1,i<=NRows(dt),i++,
Row State(dt,i)=As Row State(rowstates[i]);
);");


//save script for row states and report to data table
eval(parse("dt<<new script(reptitle,"||rowstatescript||repscript||")"));
txnelson
Super User

Re: How to extract a report name in a generic way using jsl

The issue with the JSL you have been using, is that not all window titles provide the correct information to get the Scriptable Object that can retrieve the Script.  I have found that using the initial Outline Box() from within the window is a more robust method.  However, it still will not work in all cases.  If a BY() group is specified, it will return the script for only the first BY() group.  Here is my modification to the code

Names Default To Here(1);
dt=Current Data Table();
rep=Current Report();


//data table name
dtname=dt<<Get Name();
//Report title, Scriptable Object, and finally script of report in Char form
reptitle=rep<<get window title;

// The Get Scriptable Object is a message available to the Report's
// initial Outline Box

repSO = window(reptitle)[outlinebox(1)]<<get Scriptable Object;

repscript=Char(repSO<<get script);

//get array of row states
rowstates=dt<<get row states;

//script that sets row states to values in array
rowstatescript=Eval Insert(
"Names Default To Here(1);
dt=Current Data Table();

rowstates=^Char(rowstates)^;

for(i=1,i<=NRows(dt),i++,
Row State(dt,i)=As Row State(rowstates[i]);
);");


//save script for row states and report to data table
eval(parse("dt<<new script(reptitle,"||rowstatescript||repscript||")"));
Jim
RobRobeyns
Level III

Re: How to extract a report name in a generic way using jsl

Thanks for the solution Jim and Hadley!

Much appreciated!