BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
We’ve defined a BPM to send mail to the approver when the buyer enters the PO more than the amount of his limit.
the BPM looks like this.
and the custom code is as below
Erp.Tables.POHeader POHeader;
Erp.Tables.PurAgent PurAgent;
Erp.Tables.Vendor Vendor;
string approval = string.Empty;
string strLineDesc = string.Empty;
string strVendorName = string.Empty;
var POH = (from POHeader1 in ttPOHeader where POHeader1.Company == Session.CompanyID orderby POHeader1.PONum descending select POHeader1).FirstOrDefault();
if (POH != null)
{
POHeader = (from POHeaderRow in Db.POHeader
where POHeaderRow.Company == Session.CompanyID
&& POHeaderRow.PONum == POH.PONum
select POHeaderRow).FirstOrDefault();
if (POHeader != null)
{
/*Get Line Description BEGIN*/
foreach (var ttPODetailResults in (from ttPODetailRow in Db.PODetail
where ttPODetailRow.Company == Session.CompanyID
&& ttPODetailRow.PONUM == POHeader.PONum
select ttPODetailRow))
{
if (String.IsNullOrEmpty(strLineDesc))
{
strLineDesc = Convert.ToString(ttPODetailResults.POLine) + ". " + ttPODetailResults.LineDesc + ", Qty: " + String.Format("{0:0}",ttPODetailResults.OrderQty) + ", Unit Price: " + String.Format("{0:0.00}",ttPODetailResults.UnitCost) + ", Cost: " + String.Format("{0:0.00}",ttPODetailResults.OrderQty * ttPODetailResults.UnitCost);
}
else
{
strLineDesc = strLineDesc + "\n" + Convert.ToString(ttPODetailResults.POLine) + ". " + ttPODetailResults.LineDesc + ", Qty: " + String.Format("{0:0}", ttPODetailResults.OrderQty) + ", Unit Price: " + String.Format("{0:0.00}", ttPODetailResults.UnitCost) + ", Cost: " + String.Format("{0:0.00}", ttPODetailResults.OrderQty * ttPODetailResults.UnitCost);
}
}
/*Get Line Description END*/
/*Get Supplier Name BEGIN*/
Vendor = (from VendorRow in Db.Vendor
where VendorRow.Company == Session.CompanyID
&& VendorRow.VendorNum == POHeader.VendorNum
select VendorRow).FirstOrDefault();
if (Vendor != null)
{
strVendorName = Vendor.Name;
}
/*Get Supplier Name END*/
approval = POHeader.ApprovalStatus;
var ReqPurAgent = (from PurAgentRow in Db.PurAgent
where PurAgentRow.Company == Session.CompanyID
&& PurAgentRow.BuyerID == POHeader.BuyerID
select PurAgentRow).FirstOrDefault();
var currentPurAgent = (from PurAgentRow in Db.PurAgent
where PurAgentRow.Company == Session.CompanyID
&& PurAgentRow.BuyerID == approval
select PurAgentRow).FirstOrDefault();
if (ReqPurAgent != null)
{
if (ReqPurAgent.EMailAddress != null)
{
if (POH != null)
{
if (strLineDesc != null)
{
var subject = string.Format("{0} Purchase Order : {1} Ordered By: {2} is {3} ",Session.CompanyID, POHeader.PONum, ReqPurAgent.Name, POHeader.ApprovalStatus);
var mailer = GetMailer(async: true);
var message = new Ice.Mail.SmtpMail();
//message.SetFrom("rishir@jaivel.com");
message.SetFrom(currentPurAgent.EMailAddress);
message.SetTo(ReqPurAgent.EMailAddress);
message.SetSubject(subject);
message.SetBody(subject + "\nSupplier: " + strVendorName + "\n\n" + strLineDesc);
mailer.Send(message);
} /*End strLineDesc*/
} /*End if POApvMsg*/
} /*End PurAgent.EmailAddress*/
} /*End PurAgent*/
} /*End foreach*/
}
the error i got is as below:
Can anyone help us to solve the problem?
Thanks in advance
Rishi