I am trying to setup some C# code to send an email out when a CorrectiveAction field changes. I am trying to duplicate older ABL Code.
So - When I try to save my DMRCorAct.Update BPM I get a compile error to points to not being able to find DMRCorAct.ShortChar01.
I would appreciate a second set of eyeballs to see what I am missing. Here is the code I have right now:
/* Send an email to the Corrective Action Champion when the Champion Field changes */
string strSendToAddress = string.Empty;
string strSubjectMessage = string.Empty;
string strBodyMessage = string.Empty;
string strSentFromAddress = string.Empty;
string strInitiatedByName = string.Empty;
Erp.Tables.EmpBasic EmpBasic;
foreach(var ttDMRCorAct_xRow in ttDMRCorAct)
{
var ttDMRCorActRow=ttDMRCorAct_xRow;
if(ttDMRCorAct_xRow != null)
{
/* Lookup the Initiated by (DMRCorAct.AssignedTo) empl number in EmpBasic to lookup the email address */
EmpBasic=(from EmpBasic_Row in Db.EmpBasic where EmpBasic_Row.Company == ttDMRCorActRow.Company && EmpBasic_Row.EmpID == ttDMRCorActRow.AsigndTo select EmpBasic_Row).FirstOrDefault();
if(EmpBasic != null)
{
if(EmpBasic.EMailAddress.Length > 0)
{
strSentFromAddress = EmpBasic.EMailAddress;
strInitiatedByName = “ERP Admin”;
}
else
{
strSentFromAddress = "ERP.Admin@watergrem.com ";
strInitiatedByName = “ERP Admin”;
}
/* Lookup the Champion empl number in EmpBasic to lookup the email address */
EmpBasic=(from EmpBasic_Row in Db.EmpBasic where EmpBasic_Row.Company == ttDMRCorActRow.Company && EmpBasic_Row.EmpID == ttDMRCorActRow.ShortChar01 select EmpBasic_Row).FirstOrDefault();
if(EmpBasic != null)
{
if(EmpBasic.EMailAddress.Length > 0)
{
strSentFromAddress = EmpBasic.EMailAddress;
strInitiatedByName = "ERP Admin";
}
else
{
strSentFromAddress = "ERP.Admin@watergrem.com";
strInitiatedByName = "ERP Admin";
}
}
}
}
josecgomez
(Jose C Gomez)
October 28, 2016, 2:46pm
2
tt Tables do not have access to UD fields you have to use the accessors
UDField("Name)
and
SetUDField(“Name”,value)
That so confuses me - because I setup an BPM show message and the ttDMRCorAct table has all the UD Fields and I can include the ShortChar01 and it shows the proper data.
Also, I apologize for my C# ignorance - I do not understand your answer. Would I join the DMRCorAct_UD table and then assign the DMRCorAct_UD.ShortChar01 to a variable and then use that variable in my “where” section?
Thanks,
DaveO
josecgomez
(Jose C Gomez)
October 28, 2016, 3:06pm
4
Show message and drag and drop tools understand this limitation so they take care of doing the “right” thing as needed.
to access these fields in C# you need to use an accessor built in to the tt table so something like
myTTRecord.UDField<string>("MyField") // Will Return the value of the field
myTTRecord.SetUDField<string>("MyField",myValue); // Will Set it
Mr. Jose: You are the man - I am constantly amazed at your knowledge.
That worked - I had to convert the reference to a string before I could use it in the where section but it is working.
I don’t know how you ever figured out the ttDMRCorAct.UDField(“ShortChar01”) - but it works and I am grateful.
Here is my solution:
/* Send an email to the Corrective Action Champion when the Champion Field changes */
string strSendToAddress = string.Empty;
string strSubjectMessage = string.Empty;
string strBodyMessage = string.Empty;
string strSentFromAddress = string.Empty;
string strInitiatedByName = string.Empty;
string strChampionEmpID = string.Empty;
Erp.Tables.EmpBasic EmpBasic;
foreach(var ttDMRCorAct_xRow in ttDMRCorAct)
{
var ttDMRCorActRow=ttDMRCorAct_xRow;
if(ttDMRCorAct_xRow != null)
{
/* Lookup the Initiated by (DMRCorAct.AssignedTo) empl number in EmpBasic to lookup the email address */
EmpBasic=(from EmpBasic_Row in Db.EmpBasic where EmpBasic_Row.Company == ttDMRCorActRow.Company && EmpBasic_Row.EmpID == ttDMRCorActRow.AsigndTo select EmpBasic_Row).FirstOrDefault();
if(EmpBasic != null)
{
if(EmpBasic.EMailAddress.Length > 0)
{
strSentFromAddress = EmpBasic.EMailAddress;
strInitiatedByName = “ERP Admin”;
}
else
{
strSentFromAddress = "ERP.Admin@watergrem.com ";
strInitiatedByName = “ERP Admin”;
}
/* Lookup the Champion empl number in EmpBasic to lookup the email address */
strChampionEmpID = Convert.ToString(ttDMRCorActRow.UDField("ShortChar01"));
EmpBasic=(from EmpBasic_Row in Db.EmpBasic where EmpBasic_Row.Company == ttDMRCorActRow.Company && EmpBasic_Row.EmpID == strChampionEmpID select EmpBasic_Row).FirstOrDefault();
if(EmpBasic != null)
{
if(EmpBasic.EMailAddress.Length > 0)
{
strSendToAddress = EmpBasic.EMailAddress;
strInitiatedByName = "ERP Admin";
}
else
{
strSendToAddress = "ERP.Admin@watergrem.com";
strInitiatedByName = "ERP Admin";
}
}
} //if(EmpBasic != null)
} //if(ttDMRCorAct_xRow != null)
josecgomez
(Jose C Gomez)
October 28, 2016, 5:42pm
6
Actually I had a formatting issue and the code didn’t paste correctly, but I’ve corrected it now, if you go back to my response, you’ll see you can tell the function the type (string) and then you do not need to conver it.
Glad it works for you
Chris_Conn
(Chris Conn)
October 28, 2016, 10:22pm
7
@DaveOlender - Jose is superhuman when it comes to Epicor code!