Interview Questions

Monday, May 12, 2014

Workflow Email notification in ax 2009

public void insert()
{
    UserId      useridcheck;
    ;
    super();
   if(this.TrackingContext == WorkflowTrackingContext::WorkItem
        &&  this.TrackingType   ==  WorkflowTrackingType::Creation
        && this.EmailSent == NoYes::No)
       // && this.User == useridcheck)
    {
        this.emailnotification();
    }
}

void emailnotification()
{
    SysMailer  mailer ;
    str ToAddress ;
    str FromAddress = "axadmin@dhanushinfotech.net";
    str Subject;
    str B1 ;
    str B2      =   "<p>Dhanush Team</p> <p>Note: *** This is a system generated email, please do not reply ***</p>";
    str Body;
    InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
    SysCompanyUserInfo  sysCompanyUserInfo;
    SysUserInfo sysUserInfo;
    Purchtable  purchtable;
    PurchLine   purchline;
    LedgerJournalTable LedgerJournalTable;
    WorkFlowTrackingTable wftrackingtable;
    DataArea    dataArea;
    ;

    select purchtable
        where purchtable.RecId    ==  this.ContextRecId;

    select LedgerJournalTable where LedgerJournalTable.RecId == this.ContextRecId;
    if(purchtable)
    {
        //Select firstonly purchline
          //  where purchline.PurchId == purchtable.PurchId
           // &&  (purchline.ProjCategoryId == "CAT_0001" ||  purchline.ProjCategoryId == "CAT_0002" ||
           //      purchline.ProjCategoryId == "CAT_0003" ||  purchline.ProjCategoryId == "CAT_0007" ||
           //      purchline.ProjCategoryId == "CAT_0008" ||  purchline.ProjCategoryId == "CAT_0009");
        //if(purchline)
        //{
            Subject =   "Purchase order waiting for approval.";
            B1  =   "<p>Dear Sir/Madam,</p> <p>Please Approve the purchase order %1 in the company %2(%3).</p> <p>Regards,</p>";
            Body    =   B1+B2;
            select dataArea
                where dataArea.id == curext();
            ToAddress   =   sysUserInfo::find(this.User).Email;
            CodeAccessPermission::revertAssert();
            permission.assert();
            mailer    = new SysMailer();
            CodeAccessPermission::revertAssert();
            mailer.quickSend(fromaddress,toaddress,subject,strfmt(Body,purchtable.PurchId,dataArea.name,dataArea.id));
            ttsbegin;
            select forupdate wftrackingtable where wftrackingtable.RecId == this.RecId;
            wftrackingtable.EmailSent = NoYES::Yes;
            wftrackingtable.doUpdate();
            ttscommit;
        //}
    }
     if(LedgerJournalTable)
    {
            if(LedgerJournalTable.JournalType == LedgerJournalType::Payment)
            {
                    Subject =   "Vendor Payment Journal waiting for approval.";
                    B1  =   "<p>Dear Sir/Madam,</p> <p>Please Approve the Vendor Payment Journal %1 in the company %2(%3).</p> <p>Regards,</p>";
                    Body    =   B1+B2;
                    select dataArea
                        where dataArea.id == curext();
                    ToAddress   =   sysUserInfo::find(this.User).Email;
                    CodeAccessPermission::revertAssert();
                    permission.assert();
                    mailer    = new SysMailer();
                    CodeAccessPermission::revertAssert();
                    mailer.quickSend(fromaddress,toaddress,subject,strfmt(Body,LedgerJournalTable.JournalNum,dataArea.name,dataArea.id));
                    ttsbegin;
                    select forupdate wftrackingtable where wftrackingtable.RecId == this.RecId;
                    wftrackingtable.EmailSent = NoYES::Yes;
                    wftrackingtable.doUpdate();
                    ttscommit;
            }

            if(LedgerJournalTable.JournalType == LedgerJournalType::Daily)
            {
                    Subject =   "General Journal waiting for approval.";
                    B1  =   "<p>Dear Sir/Madam,</p> <p>Please Approve the General Journal %1 in the company %2(%3).</p> <p>Regards,</p>";
                    Body    =   B1+B2;
                    select dataArea
                        where dataArea.id == curext();
                    ToAddress   =   sysUserInfo::find(this.User).Email;
                    CodeAccessPermission::revertAssert();
                    permission.assert();
                    mailer    = new SysMailer();
                    CodeAccessPermission::revertAssert();
                    mailer.quickSend(fromaddress,toaddress,subject,strfmt(Body,LedgerJournalTable.JournalNum,dataArea.name,dataArea.id));
                    ttsbegin;
                    select forupdate wftrackingtable where wftrackingtable.RecId == this.RecId;
                    wftrackingtable.EmailSent = NoYES::Yes;
                    wftrackingtable.doUpdate();
                    ttscommit;
            }

    }



}

No comments:

Post a Comment