Req : Once Project Status Changed mail goes to particular Project Sales or Delivery Manager.
Add below methods in ProjStatusUpd Class :
find Sales or Deli. Mgr email Address
private email Emailaddress(RecId _recid)
{
LogisticsElectronicAddress logisticsElectronicAddress;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPartyTable dirPartyTable;
List list = new List(Types::String);
select hcmWorker
where hcmWorker.RecId == _recid
join dirPerson
where dirPerson.RecId == hcmWorker.Person
join dirPartyTable
where dirPartyTable.RecId == dirPerson.RecId
join logisticsElectronicAddress
where dirPartyTable.PrimaryContactEmail == logisticsElectronicAddress.RecId;
return logisticsElectronicAddress.Locator;
}
Send mail:
find Sales or Deli. Mgr email Address
private email Emailaddress(RecId _recid)
{
LogisticsElectronicAddress logisticsElectronicAddress;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPartyTable dirPartyTable;
List list = new List(Types::String);
select hcmWorker
where hcmWorker.RecId == _recid
join dirPerson
where dirPerson.RecId == hcmWorker.Person
join dirPartyTable
where dirPartyTable.RecId == dirPerson.RecId
join logisticsElectronicAddress
where dirPartyTable.PrimaryContactEmail == logisticsElectronicAddress.RecId;
return logisticsElectronicAddress.Locator;
}
Send mail:
public static void Mailsend(ProjTable _projTable, ProjStatus _projStatus, boolean _updateSubProj = false)
{
str sender;
str recipient;
str cc;
str subject;
str body,userid;
int i;
List toList;
List ccList;
ListEnumerator le;
Set permissionSet;
System.Exception e;
str mailServer;
int mailServerPort;
System.Net.Mail.SmtpClient mailClient;
System.Net.Mail.MailMessage mailMessage;
System.Net.Mail.MailAddress mailFrom;
System.Net.Mail.MailAddress mailTo;
System.Net.Mail.MailAddressCollection mailToCollection;
System.Net.Mail.MailAddressCollection mailCCCollection;
System.Net.Mail.AttachmentCollection mailAttachementCollection;
System.Net.Mail.Attachment mailAttachment;
ProjStatusUpd projStatusUpd;
EventInbox EventInbox,inbox;
SysUserInfo SysUserInfo;
Name name;
Email email,emailforroles;
Enumerator enumarator;
LogisticsElectronicAddress logisticsElectronicAddress;
HcmWorker hcmWorker;
DirPerson dirPerson;
DirPartyTable dirPartyTable;
List list = new List(Types::String);
PSAProjSchedRole pSAProjSchedRole;
EventRule eventRule;
ProjId projId;
str pwd;
SysEmailParameters parameters = SysEmailParameters::find();
;
projStatusUpd = ProjStatusUpd::construct(_projTable, _projStatus,_updateSubProj);
projId = _projTable.ProjId;
//projStatusUpd.Emailaddress(_projTable);
sender = SysUserInfo::find(curUserId(), false).Email;
try
{
if(_projTable.WorkerResponsibleSales)
{
list.addEnd(projStatusUpd.Emailaddress(_projTable.WorkerResponsibleSales));
}
if(_projTable.WorkerResponsible)
{
list.addEnd(projStatusUpd.Emailaddress(_projTable.WorkerResponsible));
}
if(_projTable.WorkerResponsibleFinancial)
{
list.addEnd(projStatusUpd.Emailaddress(_projTable.WorkerResponsibleFinancial));
}
ccList = strSplit(cc, ';');
// for roles workers++
while select * from pSAProjSchedRole where pSAProjSchedRole.ProjId == projId && _projStatus == ProjStatus::Scheduled
{
if(pSAProjSchedRole.Worker)
{
emailforroles = projStatusUpd.Emailaddress(pSAProjSchedRole.Worker);
if(emailforroles)
{
list.addEnd(emailforroles);
}
}
}
// for roles workers--
enumarator = list.getEnumerator();
while(enumarator.moveNext())
{
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
CodeAccessPermission::assertMultiple(permissionSet);
mailServer = SysEmaiLParameters::find(false).SMTPRelayServerName;
mailServerPort = SysEmaiLParameters::find(false).SMTPPortNumber;
mailClient = new System.Net.Mail.SmtpClient(mailServer, mailServerPort); //smtp-mail.outlook.com
mailFrom = new System.Net.Mail.MailAddress(sender);
mailTo = new System.Net.Mail.MailAddress(enumarator.current());
mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo);
mailToCollection = mailMessage.get_To();
select * from eventRule where eventRule.FormName like "Projtable";
if(eventRule.AlertFieldLabel == "Project stage" )
{
subject = strFmt(_projTable.ProjId + " : " + _projTable.Name + " " + eventRule.Subject +" " + enum2str(_projStatus));
mailToCollection.Add(enumarator.current());
mailMessage.set_Priority(System.Net.Mail.MailPriority::Normal);
mailMessage.set_Subject(subject);
mailMessage.set_Body(eventRule.Message);
mailClient.set_EnableSsl(true);
pwd = SysEmaiLParameters::password();
mailClient.set_Credentials(New System.Net.NetworkCredential(parameters.SMTPUserName, pwd));
mailClient.Send(mailMessage);
mailMessage.Dispose();
CodeAccessPermission::revertAssert();
ttsBegin;
select SysUserInfo order by SysUserInfo.Id where SysUserInfo.Id!="";
{
select maxof(inboxId) from inbox;
EventInbox.InboxId = EventInbox::nextEventId();
EventInbox.CompanyId = curext();
EventInbox.TypeId = classnum(EventType);
EventInbox.AlertTableId = tablenum(ProjTable);//2271;
EventInbox.AlertFieldId = fieldnum(ProjTable,Status);
EventInbox.TypeTrigger = EventTypeTrigger::FieldChanged;
EventInbox.AlertCreatedDateTime = DateTimeUtil::utcNow();
EventInbox.ParentTableId = 624;//2271;
EventInbox.IsRead = NOYES::No;
EventInbox.Subject = subject;
EventInbox.AlertedFor = "Project Status :" + enum2str(_projStatus);
i = strScan(enumarator.current(),"@",1,20);
EventInbox.UserId = subStr(enumarator.current(),1,i-1);
EventInbox.ShowPopup = NOYES::Yes;
EventInbox.Visible = NOYES::Yes;
EventInbox.SendEmail = NoYes::Yes;
EventInbox.Message = eventRule.Message;
EventInbox.EmailRecipient = EventInbox.UserId;
EventInbox.insert();
}
ttsCommit;
info(strFmt("Email sent .%1", EventInbox.UserId ));
}
}
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();
while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
}
}
add below line of code in Main() Method.
ProjStatusUpd::Mailsend(projTable, projStatus,updateSubProj);
add below line of code in Main() Method.
ProjStatusUpd::Mailsend(projTable, projStatus,updateSubProj);
No comments:
Post a Comment