cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • See how to interactively organize and restructure data for analysis. Register for May 29 webinar, 2pm US ET.

Discussions

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

Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

I added the JSL below as Custom Action in the Workflow builder. 

The error happened at the For loop (Error: Send Expects Scriptable Object).

While running this script in Script window, it works properly to rename columns header that contain "%, ".

 

Any idea on how to solve this to make the workflow more smooth? else, need to stop at this step to run Column Renaming script outside the WorkFlow Builder. 

 

 

dt = Current Data Table();
searchWords = "%, ";
columnName = dt << Get Column Names;
N = N Items( columnName );

For(j=1, j<= N, j++,
	x = contains(columnName[j], searchWords);
	name = Substr(columnName[j] << Get Name(), x+3);
	If(x  > 0,
		columnName[j] << Set Name(Left(name, Length(name)-1));
	);
);
6 REPLIES 6
hogi
Level XIII

Re: Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

You could ask Get Column Names with the Option "String".
Then you don't need to ask again for the column name:

dt = Current Data Table();
searchWords = "%, ";
columnName = dt << Get Column Names("String");
N = N Items( columnName );

For(j=1, j<= N, j++,
	x = contains(columnName[j], searchWords);
	If(x  > 0,
		name = Substr(columnName[j], x+3);
		Column(columnName[j]) << Set Name(Left(name, Length(name)-1));
	);
);  
hogi
Level XIII

Re: Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

PS: don't use variable names from this list:
{name, age, sex, height, weight}

:)

hogi
Level XIII

Re: Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

Add-on (slightly related) question:

Why does calling a list entry alter the list entry?


Running the first part of 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
searchWords = "%, ";
:sex << set name ("test%, SEX#");
columnName = dt << Get Column Names;
show(columnName);
columnName[1] << Get Name();
columnName[2] << Get Name();
columnName[3] << Get Name();
columnName[4] << Get Name();
columnName[5] << Get Name();
show(columnName);

N = N Items( columnName );
For(j=1, j<= N, j++,
	x = contains(columnName[j], searchWords);
	myName = Substr(columnName[j] << Get Name(), x+3);
	If(x  > 0,
		columnName[j] << Set Name(Left(myName, Length(myName)-1));
	);
);

adds colons in front of the column names:

hogi_1-1686646556309.png
and then the for loop runs as expected *)  :)

*) hm a bit surprising that it works - esp.

contains(columnName[j], searchWords);
Nita_Natchanok
Level III

Re: Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

Hi hogi

 

Thanks for the tip. 

 

I added your code into the Workflow Builder step. It was executed without error code, but nothing has changed in the data table. 

 

Noted that both of our code (with&without "String") work properly when running with Script window, but somehow it does not work in the WorkFlow Builder. 

 

I figure out that we need to use this instead. 

Column(dt, columnName[j])

 

Here is the code that works with Workflow Builder. 

searchWords = ", ";
columnName = dt << Get Column Names("String");
N = N Items( columnName );

For(j=1, j<= N, j++,
	x = contains(columnName[j], searchWords);
	colName = Substr(columnName[j], x+length(searchWords));
	If(x  > 0,
		Column(dt, columnName[j]) << Set Name(Left(colName, Length(colName)-1));
	);
);

 

 

Nita_Natchanok
Level III

Re: Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

Hi hogi

 

Thanks for the tip. 

 

I added your code into the Workflow Builder step. It was executed without error code, but nothing has changed in the data table. 

 

Noted that both of our code (with&without "String") work properly when running with Script window, but somehow it does not work in the WorkFlow Builder. 

 

I figure out that we need to use this instead. 

Column(dt, columnName[j])

Here is the code that works with Workflow Builder. 

searchWords = ", ";
columnName = dt << Get Column Names("String");
N = N Items( columnName );

For(j=1, j<= N, j++,
	x = contains(columnName[j], searchWords);
	colName = Substr(columnName[j], x+length(searchWords));
	If(x  > 0,
		Column(dt, columnName[j]) << Set Name(Left(colName, Length(colName)-1));
	);
);
hogi
Level XIII

Re: Workflow builder error for Custom Action (Error: Send Expects Scriptable Object)

Use

dt << get column reference(cols);

to get stable column references.

I just found it in Session 6: Data Tables from JSL Scripters Club Webinars.

(highly recommended!!)

 

 

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

cols= dt << get column names();
colRefs = dt << get column reference(cols);
// {Column( "name" ), Column( "age" ), Column( "sex" ), Column( "height" ),Column( "weight" )}

// load another table
Open( "$SAMPLE_DATA/Big Class Families.jmp" );	

//Column(cols[1]) << get name // doesn't work
colRefs[1] << get name; // still works

 

 

Recommended Articles