<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Column Switcher Appled to All Open reports in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734319#M91523</link>
    <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;, My bad im sorry.. I guess instead of column switcher its more esay to have 2 colList Box where user selects column to replace in 1st and column to replace with in 2nd.. Is this approach more suitable&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2024 11:41:17 GMT</pubDate>
    <dc:creator>ComplexNerd</dc:creator>
    <dc:date>2024-03-13T11:41:17Z</dc:date>
    <item>
      <title>Column Switcher Appled to All Open reports</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734298#M91520</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a script to apply column switcher to all open reports. Please guide me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;dt = Current data Table();
//Get all Open reports
wList = Get Window List( Type( "Reports" ) );

//Get Column to replace and column to replace with
win = New Window( "Set a Value",
	&amp;lt;&amp;lt;Modal,
	&amp;lt;&amp;lt;Return Result,
	H List Box(
		ColumnSwitcherObject = dt &amp;lt;&amp;lt; Column Switcher(),
		colList = dt &amp;lt;&amp;lt; Col List Box()
	),
	Button Box( "OK" ),
	Button Box( "Cancel" )
	
);

//Now i want to loop through all reports and check if data table matches then replace column with selected column

If( win["Button"] == 1,
wList = Get Window List( Type( "Reports" ) );
for(i=1,i &amp;lt;= nitems(wList),i++,
	curWin = wList[i][Outline Box( 1 )][Outline Box( 1 )];
	curWinObj = curWin &amp;lt;&amp;lt; get scriptable object;
	curWinDt = curWinObj &amp;lt;&amp;lt; Get Datatable;
		if (curWinDt == dt )
		{
			//Replace all istance of column in list box of widow and col switcher
		}
)&lt;/PRE&gt;&lt;P&gt;Please guide how to do this action.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 11:18:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734298#M91520</guid>
      <dc:creator>ComplexNerd</dc:creator>
      <dc:date>2024-03-13T11:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Column Switcher Appled to All Open reports</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734317#M91521</link>
      <description>&lt;P&gt;How do you wish to use Col List Box? Column Switcher requires you to have a single column which is then changed to other column (based on the column list on Column Switcher) and this column should be the same in all of the reports at the start.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 11:31:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734317#M91521</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-13T11:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Column Switcher Appled to All Open reports</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734319#M91523</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;, My bad im sorry.. I guess instead of column switcher its more esay to have 2 colList Box where user selects column to replace in 1st and column to replace with in 2nd.. Is this approach more suitable&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 11:41:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734319#M91523</guid>
      <dc:creator>ComplexNerd</dc:creator>
      <dc:date>2024-03-13T11:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Column Switcher Appled to All Open reports</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734350#M91526</link>
      <description>&lt;P&gt;I think that might be a bit easier. I don't have time to write proper solution, but below is an idea how I would approach this (use column switcher to change columns which you create on function call + "Ask forgiveness, not permission"). It still has hard-coded things in it, but I will get back to it later today or tomorrow and make it more robust as this is interesting problem.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Probe.jmp");
dt &amp;lt;&amp;lt; Clear Row States;

New Window("",
	Lineup box(N Col(2),
		dist = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column(:DELL_RPNBR))),
		dist2 = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column(:DELW_M1))),
		gb1 = dt &amp;lt;&amp;lt; Graph Builder(
			Size(528, 448),
			Show Control Panel(0),
			Variables(X(:Site), Y(:Lot ID)),
			Elements(Points(X, Y, Legend(3)))
		),	
		gb2 = dt &amp;lt;&amp;lt; Graph Builder(
			Size(523, 454),
			Show Control Panel(0),
			Variables(X(:DELW_M1), Y(:DELL_RPNBR)),
			Elements(Points(X, Y, Legend(3)))
		)
	)
);

nw = New Window("",
	H List Box(
		Lineup Box(N Col(2),
			Panel Box("Select Column to Change",
				fcs1 = Filter Col Selector(dt, &amp;lt;&amp;lt; Set Max Selected(1))
			),
			Panel Box("Select New Column",
				fcs2 = Filter Col Selector(dt, &amp;lt;&amp;lt; Set Max Selected(1))
			)
		),
		Panel Box("Action",
			Button Box("Change Columns"),
			Button Box("Cancel"),
		)
	)
);

update_reports = function({dt, report_list, old_col, new_col}, {Default Local},
	nw_switcher = New Window("", &amp;lt;&amp;lt; Window View("Invisible"),
		ref_colswitcher = dt &amp;lt;&amp;lt; Column Switcher(:DELL_RPNBR, {:DELW_SICR, :DELL_RPNBR});
	);
	wait(0);

	For Each({report}, report_list,
		Try(ref_colswitcher &amp;lt;&amp;lt; Link Platform(report));
	);
	wait(0);
	
	nw_switcher[ListBoxBox(1)] &amp;lt;&amp;lt; Set Selected(1);
	nw_switcher &amp;lt;&amp;lt; Close Window;
	
);

reports = Eval List({dist, dist2, gb1, gb2});

update_reports(dt, reports, "a", "b");

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 12:24:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734350#M91526</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-13T12:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Column Switcher Appled to All Open reports</title>
      <link>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734605#M91558</link>
      <description>&lt;P&gt;There seems to be few different bugs/weird interactions which are making this more difficult than I thought and because of that the code is very messy, but it seems to work on some level&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

get_reports_for_datatable = function({dt}, {Default Local},
	valid_reports = {};
	
	// This might need improvements
	report_windows = Get Window List(Type("Reports"));
	
	For Each({report_window}, report_windows,
		Try(
			cur_analytic_layer = report_window[OutlineBox(1)] &amp;lt;&amp;lt; Get Scriptable Object;
			cur_dt = cur_analytic_layer &amp;lt;&amp;lt; Get Data Table;
			If(cur_dt == dt,
				Insert Into(valid_reports, cur_analytic_layer);
			);
		,
			show(exception_msg);
		);
	);
	return(valid_reports);
);

// I would use function, but there seem to be some bugs 
swap_report_columns = Expr(

	Eval(EvalExpr(
		nw_switcher = New Window("Switcher", &amp;lt;&amp;lt; Window View("Invisible"),
			vlb2 = V List Box(
				ref_colswitcher2 = dt &amp;lt;&amp;lt; Column Switcher(Expr(NameExpr(AsColumn(dt, old_col))),
					{Expr(NameExpr(AsColumn(dt, old_col))), Expr(NameExpr(AsColumn(dt, new_col)))}
				)
			)
		);
	));
	
	Batch Interactive(1);
	For Each({report, idx}, report_list,
		//report = report_list[2]
		
		nw1 = New Window("", &amp;lt;&amp;lt; Window View("Invisible"),
			ref_colswitcher1 = dt &amp;lt;&amp;lt; Column Switcher(Expr(NameExpr(AsColumn(dt, old_col))),
				{Expr(NameExpr(AsColumn(dt, old_col))), Expr(NameExpr(AsColumn(dt, new_col)))}
			)
		);
		
		lc = Log Capture(ref_colswitcher1 &amp;lt;&amp;lt; Link Platform(report));
		ref_colswitcher1 &amp;lt;&amp;lt; Remove Column Switcher;
		nw1 &amp;lt;&amp;lt; Close Window;
		
		If(Is Missing(lc),
			Log Capture(
				Try(ref_colswitcher2 &amp;lt;&amp;lt; Link Platform(report));
			);
		);
		
		wait(0);
	);
	Batch Interactive(0);
	Try(vlb2[ListBoxBox(1)] &amp;lt;&amp;lt; Set Selected(2));
	
	wait(0);
	ref_colswitcher2 &amp;lt;&amp;lt; Remove Column Switcher;
	
	Caption(remove);

	nw_switcher &amp;lt;&amp;lt; Close Window;	
);

swap_columns = Expr(
	nw = New Window("Swap report columns", &amp;lt;&amp;lt; Type("Launcher"),
		window:dt = Current Data Table(),
		H List Box(
			Lineup Box(N Col(2),
				Panel Box("Select Column to Change",
					fcs1 = Filter Col Selector(dt, &amp;lt;&amp;lt; Set Max Selected(1))
				),
				Panel Box("Select New Column",
					fcs2 = Filter Col Selector(dt, &amp;lt;&amp;lt; Set Max Selected(1))
				)
			),
			Panel Box("Action",
				Button Box("Change Columns",
					report_list = get_reports_for_datatable(dt);
					old_col = (fcs1 &amp;lt;&amp;lt; get selected)[1];
					new_col = (fcs2 &amp;lt;&amp;lt; get selected)[1];
					Try(swap_report_columns);
				),
				Button Box("Cancel",
					fcs1 &amp;lt;&amp;lt; close window;
				),
			)
		)
	);
);

dt = Open("$SAMPLE_DATA/Probe.jmp");
dt &amp;lt;&amp;lt; Clear Row States;

dist = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column(:DELL_RPNBR)));
dist2 = dt &amp;lt;&amp;lt; Distribution(Continuous Distribution(Column(:DELW_M1)));

gb1 = dt &amp;lt;&amp;lt; Graph Builder(
	Size(528, 448),
	Show Control Panel(0),
	Variables(X(:Site), Y(:Lot ID)),
	Elements(Points(X, Y, Legend(3)))
);
gb2 = dt &amp;lt;&amp;lt; Graph Builder(
	Size(523, 454),
	Show Control Panel(0),
	Variables(X(:DELW_M1), Y(:DELL_RPNBR)),
	Elements(Points(X, Y, Legend(3)))
);

swap_columns;

Write();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 18:00:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-Switcher-Appled-to-All-Open-reports/m-p/734605#M91558</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-13T18:00:08Z</dc:date>
    </item>
  </channel>
</rss>

