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

Loop on script files

Dear jsl scripters,

 

I have a script in which I use the include instruction to call a subscript for "reporting" (inserting a JMP chart into a powerpoint file):

 

 

dt = Current Data Table();
Include( strRootPathScript || str_report_Product1) );

 

 

It works fine as long as I use 1 product. My wish is to loop on a liste of products [Product1;Product2;...]

and to replace the product name into the include instruction.

After some exotic trials around the EVAL/EXPR/SUBSTITUTE instructions, I am begging your help!

 

Thanks!!!

 

Jerome

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SDF1
Super User

Re: Loop on script files

Hi @J_Bonnouvrier1 ,

 

  In that case, all you need to do is make sure that your directory path is correctly defined (with the last backslash included), and that you need to concatenate the ".jsl" ending to make sure things work as expected.

 

As an example, I created three Product JSL files, each with the following commands, but just changing the numbers from 1, to 2, and then 3:

Names Default to Here (1);

Print("This is Product 1 JSL script");

The main JSL file is as follows:

Names Default to Here (1);

Product_List={"Product1", "Product2", "Product3"};
ScriptDir = "C:\temp\"; //Or whatever your path is.

Print("This is the main script");

For(i=1, i<=NItems(Product_List), i++,
	Include(ScriptDir||Product_List[i]||".jsl");
);

The output of running the above main code is:

 

"This is the main script"
"This is Product 1 JSL script"
"This is Product 2 JSL script"
"This is Product 3 JSL script"

 

  It will also work out if you have the ".jsl" as part of the product list, like: Product_List={"Product1.jsl", "Product2.jsl",...}; and then you would remove the ||".jsl" concatenation from the For loop. Either way, you get the same output as above. It just depends on how you want to define the Product_List list.

 

Hope this helps!,

DS

 

 

  

View solution in original post

3 REPLIES 3
SDF1
Super User

Re: Loop on script files

Hi @J_Bonnouvrier1 ,

 

  It's a little hard to generalize this to work under any circumstance, but you could loop through it given a code/file structure as I imagine it.

 

  Assuming that you know before hand the substitutions Product1, Product2, etc In your JSL code, if you do something like:

dt = Current Data Table();

For(i=1, i<=NItems(Product_List), i++,
  Include(strRootPathScript||"str_report_"||Product_List[i]);
);

 In this case, the variable Product_List would be a list of your products: Product_List={"Product1", "Product2", "Product3",...};. In the For loop, when it calls Product_List[i], it would be concatenating the ith element of Product_List. So, if i = 3, it should do the following:

 

Include(strRootPathScript||str_report_||Product_List[3]) , where I'm assuming strRootPathScript is some root path, like "C:\myfiles\JSL_code\", so that the argument you're feeding into the Include function would in this case be: "C:\myfiles\JSL_code\str_report_Product3".

 

  Is this kind of what you're after?

 

Hope this helps!,

DS

J_Bonnouvrier1
Level III

Re: Loop on script files

Hi @SDF1 ,

 

Actually I forgot to mention that str_report_Product1 is a variable giving the name of the file for each product:

str_report_Product1 = "C:\temp\report_Product1.jsl"

 

So, the solution you propose is not recognized by the script.

 

Thanks and regards,

 

Jérôme

SDF1
Super User

Re: Loop on script files

Hi @J_Bonnouvrier1 ,

 

  In that case, all you need to do is make sure that your directory path is correctly defined (with the last backslash included), and that you need to concatenate the ".jsl" ending to make sure things work as expected.

 

As an example, I created three Product JSL files, each with the following commands, but just changing the numbers from 1, to 2, and then 3:

Names Default to Here (1);

Print("This is Product 1 JSL script");

The main JSL file is as follows:

Names Default to Here (1);

Product_List={"Product1", "Product2", "Product3"};
ScriptDir = "C:\temp\"; //Or whatever your path is.

Print("This is the main script");

For(i=1, i<=NItems(Product_List), i++,
	Include(ScriptDir||Product_List[i]||".jsl");
);

The output of running the above main code is:

 

"This is the main script"
"This is Product 1 JSL script"
"This is Product 2 JSL script"
"This is Product 3 JSL script"

 

  It will also work out if you have the ".jsl" as part of the product list, like: Product_List={"Product1.jsl", "Product2.jsl",...}; and then you would remove the ||".jsl" concatenation from the For loop. Either way, you get the same output as above. It just depends on how you want to define the Product_List list.

 

Hope this helps!,

DS