UD table lookup on column

I want to convert the code below to make the column dynamic. I want to look up what is in the column of an input that is set in the configurator. The obvious choice to me was to use column. I also tried columns and column_value but did not have any luck without hard coding the column name into the syntax. I also tried to use a parameter in the UD method to pass the column name in, but that didn’t work either. Am I missing something easy to get this to work or should I go back to my original code that was working?

if (Inputs.cmb_model.Value != “”){

var model = Db.UD02.Where(u => u.Company == “company” && u.Part_c == Inputs.cmb_model.Value).Select(u=>new{u.MSRP_c}).FirstOrDefault();

Inputs.dec_modelprice.Value = (model != null) ? model.MSRP_c : 0;

}

Assuming you tried the .Field, do you know the proper type to expect?

If I read this correctly I think this is what you are looking for?

string ControlName  = "myCombo"; // Could be from UD parameter

if (((InputValueBound<String>)Inputs[ControlName].Value).Value != "Stuff"){
	// Do something cool here
}

I am fairly new to the linq statements and I did not try the .field, but I will see what I can find on that. Thanks!

I am not following how this statement relates to the UD table column. I am sorry, I am fairly new to the E10 language.

I read what you were looking for incorrectly then :slight_smile:
You are looking to make the highlighted fields dynamic?
image

Yes, I created new columns in the UD table but instead of listing them I want to use an input form the configurator. I can’t seem to figure out the context to set a column equal to a value, though. Works great if I know what column I want and put it in through :slight_smile:

This probably isn’t the most elegant solution but I think this would work:

string sReturnColumn = "MSRP_c";

var model = (from row in Db.UD02
      where row.company == "company" &&
      row.Part_c == Inputs.cmb_model.Value 
      select row).FirstOrDefault();

return model[sReturnColumn].ToString();

it’s returning a lot more data (the entire row) than you need and then selecting the column that you ask for specifically.

1 Like