cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Stefan_Moser
Level II

Adding explicit table reference in JSL code leads to unexpected results

I have a short JSL script that I'm looking to add to a larger automated workflow. The intent is to iterate over the values in a column (layer_type) and if it finds any value other than SSOD the code should return 1. If all values in the columns are 'SSOD' then it should return 0. This is being used in a if/else split in a workflow to throw an error. In general if you have recommendations of a better way to code this up I'm all ears. 

 

Given the existing code - I've pulled it out of the workflow to debug. The code works as intended when I run it in a JSL window with the correct data table selected. However because I'm inserting it into a workflow for users I want to be explicit about the data table name as I've found that to be more robust, however when I add the first line of code it no longer works as intended - it still runs but always returns '1' regardless of the column values.

 

The below JSL yields the expected results when run in a script window referencing the table (attached). Note the table as attached will return '0'. Modify a value in a single row in the 'layer_type' column to anything else and it should return 1.

Stefan_Moser_0-1745881433448.png

 

Summarize( meas = by( :layer_type ) );
result = 0;

For( i = 1, i <= N Items( meas ), i++,
	If( meas[i] != "SSOD",
		result = 1;
		Break();
	)
);

result;

 However, when I modify only the beginning of the JSL to explicitly reference the table it no longer works - when I change a single value in the 'layer_type' column to anything other than SSOD it continues to return '0'. In fact I've tested this both ways by commenting out the Data Table( "layer_type_forum_help" ) << code and it seems it always returns what was previously returned when the block started with the 'Summarize' command

Data Table( "layer_type_forum_help" ) << Summarize( meas = by( :layer_type ) );
result = 0;

For( i = 1, i <= N Items( meas ), i++,
	If( meas[i] != "SSOD",
		result = 1;
		Break();
	)
);

result;

Thanks you pre-emptively for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Adding explicit table reference in JSL code leads to unexpected results

Your syntax for the Summary() function is incorrect.  See the Scripting Index for definition, syntax and examples

Summarize(Data Table( "layer_type_forum_help" ),  meas = by( :layer_type ) );
result = 0;

For( i = 1, i <= N Items( meas ), i++,
	If( meas[i] != "SSOD",
		result = 1;
		Break();
	)
);

result;
Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Adding explicit table reference in JSL code leads to unexpected results

Your syntax for the Summary() function is incorrect.  See the Scripting Index for definition, syntax and examples

Summarize(Data Table( "layer_type_forum_help" ),  meas = by( :layer_type ) );
result = 0;

For( i = 1, i <= N Items( meas ), i++,
	If( meas[i] != "SSOD",
		result = 1;
		Break();
	)
);

result;
Jim

Re: Adding explicit table reference in JSL code leads to unexpected results

I think you can simply use the function call,

N Items( meas )

To determine the answer. You are looking for a single value in this column. It should therefore result in a single group from the Summarize() function call. If the number of items is greater than one, you have at least one row with a different string.

Data Table( "layer_type_forum_help" ) << Summarize( meas = By( :layer_type ) );
result = N Items( meas ) > 1;
Stefan_Moser
Level II

Re: Adding explicit table reference in JSL code leads to unexpected results

Thanks @Mark_Bailey  I considered this but for the error check it is possible there could be one value that is not the desired one (SSOD) and I want to differentiate that. 

Re: Adding explicit table reference in JSL code leads to unexpected results

*** Update: I apologize for my reply below. It might help someone, but it does not address your request. What do you want? Do you want to know if any value does not match and return after the first occurrence of a non-conforming value?

 

You said, "I have a short JSL script that I'm looking to add to a larger automated workflow. The intent is to iterate over the values in a column (layer_type) and if it finds any value other than SSOD the code should return 1. If all values in the columns are 'SSOD' then it should return 0. "

Summarize( meas = By( :layer_type ) );
result = N Items( meas ) > 1;

This case exhibits only the value "SSOD" so it should return 0:

same.png

The result is 0:

same result.png

Another case exhibits values other than "SSOD: so should return 1

DIFF.png

The result is 1:

diff result.png

 

Stefan_Moser
Level II

Re: Adding explicit table reference in JSL code leads to unexpected results

@Mark_Bailey - no worries it's tangentially related and I did ask about it in the post so appreciate your time.

 

I can do a better job of explaining where that solution doesn't return the desired result. The examples in your most recent post are accurate and return the desired result. The third scenario is where the column contains all values that are not SSOD. For example, the entire layer_type is filled with 'NAIL'. In that case I believe your code would return 0. The desired result would still be 1 (since not all values are SSOD).

Recommended Articles