List Reference IssuesI have a script that takes user input through a setup window and based on that info processes nonconformance cost data. I'm having issues with using the data from the input NC codes and dispositions (see attached picture or run the script) as part of the costcols function. The goal of the function is to remove any rows where the :DISP.TYPE is not what one of the checked disposition options and then for each entered code create a new column that multiples :NC.QTY * :COST. The script runs correctly except for that one function. The only thing I cna think of is there is some issue with how I set up or reference the different lists. There are two lists for the NC codes and two for the disposition. The first for each is the checkbox result to determine if action needs to be taken and the second contains the values to search for in the script. The codes are vairable, but the dispositions are hardcoded to correspond with the given checkboxes.
addcols = Function({},
CCT<<NEW column=""></NEW>Re: List Reference IssuesMoving forward, now that I've got all the columns for the entered codes showing up correctly is to create summary tables per NC code over different time ranges (month, year, etc.). I've done summary tables before, but never wiht a variable number of columns since the user can enter up to 5 NC codes. Is there a way to do this?
Re: List Reference IssuesThat makes things much simpler! I'll start using that format from now on.
Re: List Reference IssuesAdding in the Eval List function fixed the problem! Thanks!
Re: List Reference IssuesI was going to suggest that you use EvalList as well. When you reference "dispchecks[d]" it only evaluates to the variable in that position, which can never be equal to 1. Eval List will make the actual values appear in the list.
Also, I have a tip for future long If statements. You can put many conditions within the same If statement, greatly reducing the complexity when you have a large number of conditions. The excerpt below is equivalent to the group of If statements in your formula column.
If(
Month( :DETECT.DATE ) == 1, "January",
Month( :DETECT.DATE ) == 2, "February",
Month( :DETECT.DATE ) == 3, "March",
Month( :DETECT.DATE ) == 4, "April",
Month( :DETECT.DATE ) == 5, "May",
Month( :DETECT.DATE ) == 6, "June",
Month( :DETECT.DATE ) == 7, "July",
Month( :DETECT.DATE ) == 8, "August",
Month( :DETECT.DATE ) == 9, "September",
Month( :DETECT.DATE ) == 10, "October",
Month( :DETECT.DATE ) == 11, "November",
Month( :DETECT.DATE ) == 12, "December",
"You did something wrong"
);
Re: List Reference IssuesMaybe the use of evallist() is needed here. Try running this code:
code1a = "aaa";
code2a = "bbb";
code3a = "ccc";
code4a = "ddd";
code5a = "eee";
codechecks1 = {code1a, code2a, code3a, code4a, code5a};
codechecks2 = evallist({code1a, code2a, code3a, code4a, code5a});
print(codechecks1);
print(codechecks2);
As you can see, the evallist() converts the variable names to their actual values, which is what I think you want.
Re: List Reference IssuesThat makes sense. Thanks for pointing that out. I've updated that section of the script, but am still struggling with the original issue of referencing the lists.
Re: List Reference IssuesI found a potential trouble spot in your code:
CCT<SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN>Select Where<SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">:</SPAN>DISP<SPAN class="token punctuation">.</SPAN>TYPES <SPAN class="token operator">==</SPAN> <SPAN class="token string">"NOTDEFINED"</SPAN> <SPAN class="token operator">|</SPAN> <SPAN class="token punctuation">:</SPAN>DISP<SPAN class="token punctuation">.</SPAN>TYPES <SPAN class="token operator">==</SPAN> <SPAN class="token string">"DEVIATE"</SPAN> <SPAN class="token operator">|</SPAN> <SPAN class="token punctuation">:</SPAN>DISP<SPAN class="token punctuation">.</SPAN>TYPES <SPAN class="token operator">==</SPAN> <SPAN class="token string">"REVIEWED & REVERSED"</SPAN> <SPAN class="token operator">|</SPAN> <SPAN class="token punctuation">:</SPAN>DISP<SPAN class="token punctuation">.</SPAN>TYPES <SPAN class="token operator">==</SPAN> <SPAN class="token string">"SCRAP"</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
CCT<SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN>Delete Rows<SPAN class="token punctuation">;</SPAN>
CCT<SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN>Clear Select<SPAN class="token punctuation">;</SPAN>
If your select statement doesn't find anything you'll get an error message in the log about nothing being selected Safer to do this:
del_rows = CCT << get rows Where(:DISP.TYPES == "NOTDEFINED" | :DISP.TYPES == "DEVIATE" | :DISP.TYPES == "REVIEWED & REVERSED" | :DISP.TYPES == "SCRAP");
if (nrows(del_rows) > 0,
cct << delete rows(del_rows);
);