web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

PO confirmation and email triggering

(0) ShareShare
ReportReport
Posted on by 327

hi all

i have done one job for mail triggering in that i selected confirmed PO order.that is working fine for me.now i am facing issue where i need to write that method if purchase order status changed to confirm.that conformation button is action type class.that is PURCHFORMLETTER. in that lot of method is there in which method i need to write my method for mail triggering.If Po confirm means it should trigger mail wich ever  po i selected.help me pls..thank you

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Hi karthik143,

    You can try to override PurchPurchOrderJournalPost.postJournalPost() method, it will be executed after PO order is posted.

  • karthik143 Profile Picture
    327 on at

    thanks for replay ievgen Miroshnikov and how to select particular PO means i am confriming one po only so i nedd to select that po only....

    how to pass arguments can you please help me this is my code

    this is my job.thanks in advance

    static void ITTI_EmailTrigger(Args _args)

    {

    SysEmailParameters parameters = SysEmailParameters::find();

    SMTPRelayServerName relayServer;

    SMTPPortNumber portNumber;

    SMTPUserName userName;

    SMTPPassword password;

    Str1260 subject ;

    InteropPermission interopPermission;

    SysMailer  mailer = new SysMailer();

    System.Exception e;

    PurchTable PurchTable;

    PurchLine  PurchLine;

    str PurchaseId;

    str ItemId,ItemName,Qty,UnitPrice,NetAmount;

    str  htmlstr;

    int i;

    if (parameters.SMTPRelayServerName)

       {

    relayServer = parameters.SMTPRelayServerName;

    portNumber = parameters.SMTPPortNumber;

    userName = parameters.SMTPUserName;

    password = SysEmailParameters::password();

       }

    else

    //relayServer = parameters.SMTPRelayServerName;

       {

    relayServer = parameters.SMTPServerIPAddress;

    portNumber = parameters.SMTPPortNumber;

    userName = parameters.SMTPUserName;

    password = SysEmailParameters::password();

       }

    subject = "Update On Purchase Order";

       while  select PurchTable join PurchLine where PurchTable.PurchId==PurchLine.PurchId && PurchTable.DocumentState==VersioningDocumentState::Confirmed

         && PurchLine.PurchId=='INMF-000082'

           {

       PurchaseId=PurchTable.PurchId;

       ItemId=PurchLine.ItemId;

       ItemName=PurchLine.Name;

       Qty=num2str(PurchLine.PurchQty,10,3,1,2);

       UnitPrice=num2str(PurchLine.PurchPrice,10,3,1,2);

       NetAmount=num2str(PurchLine.LineAmount,10,3,1,2);

             if(i==1)

           {

               htmlstr+="<html>";

               htmlstr+='<P>Dear Sir/Madam The purchase OrderNumber '+PurchaseId+' has been confimed.The Details as follows</P>';

           }

       i++;

           }

    CodeAccessPermission::revertAssert();

    try

    {

       interopPermission = new InteropPermission(InteropKind::ComInterop);

       interopPermission.assert();

       //instantiate email

       mailer.fromAddress(userName);

      // mailer.tos().appendAddress("shravan.j@itti.com");

        mailer.tos().appendAddress("kartheek.mv@itti.com");

       mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);

       mailer.subject(subject);

       mailer.htmlBody(htmlstr);

       mailer.sendMail();

       CodeAccessPermission::revertAssert();

       info("Email has been send!");

    }

           catch (Exception::CLRError)

    {

           e = ClrInterop::getLastException();

           while (e)

              {

                   info(e.get_Message());

                   e = e.get_InnerException();

              }

     CodeAccessPermission::revertAssert();

     info ("Failed to Send Email some Error occure");

    }

    }

  • Mea_ Profile Picture
    60,286 on at

    This code looks like a job, what are you trying to do with this job ?

  • karthik143 Profile Picture
    327 on at

    i created class

    inside that i written a method called ITTI_POmailtriggering

    please check that and i need to pass in that code which ever po i confirmed that only i should send mail. how to pass that particular record

    thanks in advance.......

    public void ITTI_PoMailTrigger()

    {

       SysEmailParameters     parameters = SysEmailParameters::find();

       SMTPRelayServerName    relayServer;

       InteropPermission      interopPermission;

       System.Exception       e;

       if (parameters.SMTPRelayServerName)

       {

           relayServer  = parameters.SMTPRelayServerName;

           portNumber   = parameters.SMTPPortNumber;

           userName     = parameters.SMTPUserName;

           password     = SysEmailParameters::password();

       }

      else

       {

           relayServer  = parameters.SMTPServerIPAddress;

           portNumber   = parameters.SMTPPortNumber;

           userName     = parameters.SMTPUserName;

           password     = SysEmailParameters::password();

       }

          while  select PurchTable join PurchLine where PurchTable.PurchId==PurchLine.PurchId && PurchTable.DocumentState==VersioningDocumentState::Confirmed

          {

                  PurchaseId=PurchTable.PurchId;

                  ItemId=PurchLine.ItemId;

                  ItemName=PurchLine.Name;

                  Qty=num2str(PurchLine.PurchQty,10,3,1,2);

                  UnitPrice=num2str(PurchLine.PurchPrice,10,3,1,2);

                  NetAmount=num2str(PurchLine.LineAmount,10,3,1,2);

             if(i==1)

               {

                     htmlstr+="<html>";

                     htmlstr+='<P>Dear Sir/Madam The purchase OrderNumber '+PurchaseId+' has been confimed.The Details as follows</P>';

               }

                 i++;

          }

               CodeAccessPermission::revertAssert();

               try

              {

                   interopPermission = new InteropPermission(InteropKind::ComInterop);

                   interopPermission.assert();

                   mailer = new SysMailer();

                   mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);

                   mailer.fromAddress("kartheek.mv@itti.com");

                   mailer.tos().appendAddress("kartheek.mv@itti.com");

                   mailer.subject(subject);

                   mailer.htmlBody(htmlstr);

                   mailer.sendMail();

                   CodeAccessPermission::revertAssert();

                   info("Email has been send!");

              }

              catch (Exception::CLRError)

              {

                 e = ClrInterop::getLastException();

                 while (e)

                {

                   info(e.get_Message());

                   e = e.get_InnerException();

                }

                 CodeAccessPermission::revertAssert();

                 info ("Failed to Send Email some Error occure");

              }

    }

  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    So you can override PurchPurchOrderJournalPost.postJournalPost()

    with next code

    public void postJournalPost()
    {
        super();
        ITTI_POmailtriggering::ITTI_PoMailTrigger(vendPurchOrderJour);
    }


     Then you need to modify you method

    public void ITTI_PoMailTrigger(VendPurchOrderJour      _vendPurchOrderJour)
    {
        SysEmailParameters     parameters = SysEmailParameters::find();
       SMTPRelayServerName    relayServer;
       InteropPermission      interopPermission;
       System.Exception       e;
       if (parameters.SMTPRelayServerName)
       {
           relayServer  = parameters.SMTPRelayServerName;
           portNumber   = parameters.SMTPPortNumber;
           userName     = parameters.SMTPUserName;
           password     = SysEmailParameters::password();
       }
      else
       {
           relayServer  = parameters.SMTPServerIPAddress;
           portNumber   = parameters.SMTPPortNumber;
           userName     = parameters.SMTPUserName;
           password     = SysEmailParameters::password();
       }
          while  select PurchTable join PurchLine where PurchTable.PurchId==PurchLine.PurchId
              && PurchTable.PurchId == _vendPurchOrderJour.PurchId
          {
                  PurchaseId=PurchTable.PurchId;
                  ItemId=PurchLine.ItemId;
                  ItemName=PurchLine.Name;
                  Qty=num2str(PurchLine.PurchQty,10,3,1,2);
                  UnitPrice=num2str(PurchLine.PurchPrice,10,3,1,2);
                  NetAmount=num2str(PurchLine.LineAmount,10,3,1,2);
             if(i==1)
               {
                     htmlstr+="<html>";
                     htmlstr+='<P>Dear Sir/Madam The purchase OrderNumber '+PurchaseId+' has been confimed.The Details as follows</P>';
               }
                 i++;
          }
               CodeAccessPermission::revertAssert();
               try
              {
                   interopPermission = new InteropPermission(InteropKind::ComInterop);
                   interopPermission.assert();
                   mailer = new SysMailer();
                   mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
                   mailer.fromAddress("kartheek.mv@itti.com");
                   mailer.tos().appendAddress("kartheek.mv@itti.com");
                   mailer.subject(subject);
                   mailer.htmlBody(htmlstr);
                   mailer.sendMail();
                   CodeAccessPermission::revertAssert();
                   info("Email has been send!");
              }
              catch (Exception::CLRError)
              {
                 e = ClrInterop::getLastException();
                 while (e)
                {
                   info(e.get_Message());
                   e = e.get_InnerException();
                }
                 CodeAccessPermission::revertAssert();
                 info ("Failed to Send Email some Error occure");
              }
    }


  • karthik143 Profile Picture
    327 on at

    sorry ievgen Miroshnikov that is not working

  • Mea_ Profile Picture
    60,286 on at

    What exactly is not working ?

  • karthik143 Profile Picture
    327 on at

    what ever you said same thing i have done but its not triggering any mail with POnum

  • Mea_ Profile Picture
    60,286 on at

    Did you try to debug ?

    Did you compile and run CIL ?

    Please remember we are trying to help you however no one except you have access to your system and don't know what you have done, how are you testing this and so on.

    So if you won't provide any details and continue saying "it is not working, help me" no one will be able to help you.

  • karthik143 Profile Picture
    327 on at

    kk ill try with debugger

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans