Using a Customized field in a BPM

I have spend almost all the day looking alternatives:

I created a Customized Field in the Employee table (EmpBasic).

When the user is created, we need to add a record in the Warehouse Bin table (WhseBin) for an specific warehouse created for employees. To do it, I am trying to create a BPM in Employee.Update.

I have the next code:

bool bExists = false;
string sTOOLSEMP = "TOOLSEMP";

using (var txscope = IceDataContext.CreateDefaultTransactionScope())
{
  foreach(var ttEmpBasic_iterator in(from ttEmpBasic_Row in ttEmpBasic select ttEmpBasic_Row))
  {
    var ttEB = ttEmpBasic_iterator;  

    foreach (var tWhseBin in Db.WhseBin.Where( tWhseBin => tWhseBin.Company == Session.CompanyID && tWhseBin.WarehouseCode == sTOOLSEMP && xWhseBin.BinNum == ttEB.ClockNo_c)) 
    {
      bExists = true;
      xWhseBin.ZoneID = ttEB.WhseZone_c;  
    }

    if (!bExists) 
    {
      // Add row
      WhseBin newRow = new WhseBin();
      Db.WhseBin.Insert(newRow);

      newRow.Company = Session.CompanyID;
      newRow.WarehouseCode = sTOOLSEMP ;
      newRow.EmpID_c = ttEB.EmpID;
      newRow.BinNum = ttEB.ClockNo_c;
      newRow.Description = ttEB.Name;
      newRow.ZoneID = ttEB.WhseZone_c; 
    }
  }
  
  Db.Validate();
  txscope.Complete();
}

I receive the error:
1.
"EmpBasicRow" doe snot contain a definition for ClockNo_c and no accesible extension method 'ClocKNo_c' accepting a first argument of type 'EmpBasicRow' could be found (are you missing a using directive or an assembly reference?)
2. 
"EmpbasicRow" doe snot contain a definition for WhseZone_c and no accesible extension method 'WhseZone_c' accepting a first argument of type 'EmpBasicRow' could be found (are you missing a using directive or an assembly reference?)

Those two fields with the error are customized fields. I just entered Constants to test it and the record is saved, but the custom fields are not recognized.

This is weird because those fields are listed to be used in a Show Message and the values are displayed.

Thank you for your comments,

@ggrimaldo I think you need to use UDField and SetUDField.

myTTRecord.UDField<string>("MyField") // Will Return the value of the field
myTTRecord.SetUDField<string>("MyField",myValue); // Will Set it

I think this will work. 
newRow.SetUDField("EmpID_c",ttEmpID);
newRow.BinNum = ttEB.UDField<string>("ClockNo_c");

2 Likes

It’s because you’re trying to access UD fields by an object reference in the tt tables. You can’t access UD fields like this directly (“table.UDField”), so instead access them like this:

ttEB[“ClockNo_c”]
ttEB[“WhseZone_c”]

Thank you Mathew.

It allows to save. It compiles, but when I run it, I receive the message that needs to be converted from Object to String.
I just tried:
newRow.BinNum = ttEB[“ClockNo_c”].ToString();
But it didn’t work and I just changed to:
newRow.BinNum = Convert.ToString(ttEB[“ClockNo_c”]);
but I receive the next error message:
LINQ to Entities does not recognize the method ‘System.String ToString(System.Object)’ method, and this method cannot be translated into a store expression.

I am looking an alternative to solve this. Thank you very much!

Ready.

I just defined variables as string and assigned the values to the variables.

string sClockNo;

sClockNo = ttEB[“ClockNo_c”].ToString();

newRow.BinNum = sClockNo;

Thank you very much for your help!