CFG Keep When Rule Code

I am trying to write code to bring a part in when the calculation is less than an certain integer. The code editor says it is correct but the rule does not function. It brings it in on every occasion. Can some one tel me where I went wrong? Thanks,

if(System.Convert.ToInt32(Inputs.cmbBarWidth.Value.Substring(0,2).Trim()) * 12 / System.Convert.ToInt32(Inputs.cmbRowSpacing.Value.Substring(0,2).Trim()) < 13);

{
return Inputs.chkDistributor.Value = true;
}

Hello Marty,

You may want to create a couple of temp variables to make sure your int32’s are, well, int32. Put your conversion in a try catch.

Also. What do you want chkDistributor to be if false? Might want an else in there - if that’s the logic you want.

Mark W.

Mark -

If Check Box is false I don’t want the part coming in. I am new to C# and learning as I go. The convert intergers are reading other dropdown box Values in the CFG. So I don’t know how to do the temp variables. I will look into that, Thanks,

I think @Mark_Wonsil is saying to create a couple of int variables within the code for debugging. Something like this:

try
{
    int barWidth = System.Convert.ToInt32(Inputs.cmbBarWidth.Value.Substring(0,2).Trim());
    int rowSpacing = System.Convert.ToInt32(Inputs.cmbRowSpacing.Value.Substring(0,2).Trim());
    
    QuoteDtl.QuoteComment += "cmbBarWidth.Value = " + Inputs.cmbBarWidth.Value + " | barWidth = " + barWidth + "\r\n";
    QuoteDtl.QuoteComment += "cmbRowSpacing.Value = " + Inputs.cmbRowSpacing.Value + " | rowSpacing = " + rowSpacing + "\r\n";
}
catch {	return false; }

if ( (barWidth * 12 / rowSpacing) < 13 )
{
    Inputs.chkDistributor.Value = true;
    return false;
}
else
{
    Inputs.chkDistributor.Value = false;
    return false;
}

It is a bit odd to be setting input values in the Keep When rules - usually you would do that in the configuration session (either on a combobox field change or a page event) so that it can be displayed. Then your Keep When rule expression simply becomes:

return Inputs.chkDistributor.Value;
1 Like

I made some assumptions that you were trying to include the checkbox in your expression since this is a method rule. I would use this and avoid the try / catch if you can.

int cmbBarWidth = 0;
int cmbRowSpacing = 0;
bool ReturnValue = false;
if( Int32.TryParse(Inputs.cmbBarWidth.Value.Substring(0,2).Trim(),out cmbBarWidth) && Int32.TryParse(Inputs.cmbRowSpacing.Value.Substring(0,2).Trim(),out cmbRowSpacing )) 
	{
		ReturnValue =  cmbBarWidth * 12 / cmbRowSpacing < 13 && Inputs.chkDistributor.Value;
	}
return ReturnValue;
1 Like

Dan -

I used your code. The syntax says correct but it still brings the part in on every selection. The same as my code I started with.

Maybe I am Not presenting this correctly.

I have two drop down values that use the calculation to figure the quantities for Row Units by Barwidth and Row spacing.
So I have a Part (Dist) that needs to come in if the row units are less than 13 and a Checkbox is true.
I need to do the calculation to get the number of row units to decide whether to bring the (Dist) on the Keep when rule for (Dist).

Thanks,

Marty,

In your code above you have the return trapped in an if statement, so that it might or might not be executed.

You might try something like:

return System.Convert.ToInt32(Inputs.cmbBarWidth.Value.Substring(0,2).Trim()) * 12 / System.Convert.ToInt32(Inputs.cmbRowSpacing.Value.Substring(0,2).Trim()) < 13;

This evaluates the comparison and returns the boolean result. If the value is < 13 it would return ‘true’ which would keep your part. Otherwise it would return ‘false’ which would not keep the part (assuming the second part of the keep rule calls for the true condition).

Does that help any?

Thanks,

Joe

And I’m just curious. What kind of configurator do you have going there? Looks like farm equipment to me.

Joe

Manure Application Toolbars. You can Lok at them on our website. https://www.puckenterprises.com/

Thanks,

Nice. In a former life I worked at a tillage and cultivation equipment manufacturer. Not too much different. Some of our equipment applied a different kind of fertilizer. :slight_smile:

Good luck!

Joe

1 Like

Thanks JD -

I had the whole thing backwards. This works also

return Inputs.chkDistributor.Value = true && System.Convert.ToInt32(Inputs.cmbBarWidth.Value.Substring(0,2).Trim()) * 12 / System.Convert.ToInt32(Inputs.cmbRowSpacing.Value.Substring(0,2).Trim()) < 13 ;

This is what I was trying to do>

Good deal. Thanks for letting me know.

Joe