I was having an issue with a more complicated script and wrote a simple test script to try and fix the issue, but can't figure out what's wrong. It's probably glaringly obvious, but I've been looking at it for too long to notice. I create a table with :Disposition Type, :NC Code, and :NC Qty. The original script takes user input to create the list of codes, but here I predefined the list. I want to create a column for each code listed in the codes list that copies over the value in :NC Qty if :NC Code matches the code from the list. It recognizes codes[c] to name the column, but not in the column formula. I've also tried using Contains instead of == in the formula, but that didn't seem to make a difference.
New Table( "NC Qty Col Test",
Add Rows( 5 ),
New Column( "Disposition Type",
Character,
"Nominal",
Set Values(
{"SCRAP-R", "SCRAP-DNR", "DEVIATE-MATERIAL", "DEVIATE-PROCESS",
"DEVIATE-PRODUCT"}
)
),
New Column( "NC Code",
Character,
"Nominal",
Set Values( {"007", "014", "020", "007", "008"} )
),
New Column( "NC Qty",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 2, 3, 4, 5] )
)
);
codes = {"007", "014"};
For(c=1, c<=NItems(codes), c++,
New Column("Code " || codes[c] || " NC Qty", Numeric, Continuous, Formula(If(:NC Code==codes[c], :NC Qty, 0 )));
);