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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to send SMS to customers by using SMS API on invoicing from AX?

(0) ShareShare
ReportReport
Posted on by 1,813

Hii,

We want to send SMS to customer mobile numbers with a thank you message and a survey link from Dynamics AX 2012 R2.

It will be sent automatically once the invoice will be generated for a sales order.

We have an API from our SMS service provider company that we want to integrate in AX.

Please guide how I can consume this SMS API in AX to send messages on invoice creation to customer mobile numbers?

Thanks, 

  

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    How to use the API depends on what kind of API it is.

    My piece of advice is not calling the API synchronously from invoice posting, to prevent slowing down or blocking posting if something fails with SMS. A good approach may be inserting a message to a separate table or a message queue and sending SMS later from outside the transaction of invoice posting.

  • Rana Anees Profile Picture
    1,813 on at

    Hii Martin,

    Need your opinion what I came to know.

    I need to create a AIF service  (inbound or outbound?) that will be called when an invoice is generated (for a specific customer group only i.e. cash). I dont need synchronously.

    Will create ASP.Net web project and it will use this new AIF service. This ASP.Net application will also have reference for SMS provider API. So , here both AX AIF service and SMS API will communicate? Is this the right approach?

    Thanks,

  • Suggested answer
    A.Prasanna Profile Picture
    8,223 on at

    Hope this will help.

    axatoz.wordpress.com/.../how-to-send-text-messages-from-dynamics-ax-using-twilio

    Thanks & Regards,

    Amith Prasanna

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    I'm not sure that your design meets your requirements. If you create a separate web application calling AIF services, how will the web application knows that an invoice has been posted in AX and that it should call an AX service? If you do it in this way, you'll have to try to call the service periodically (e.g. every minute) to see if anything has been posted.

    It seems that you're asking how to use the SMS API from AX; you've already decided not to do it and use a separate web application instead. I'm not sure way, but it's definitely a possible design. Then you should consider exposing a web service from the web application that you would call from AX. Don't forget to implement authentication and such things (which may be an argument against building a new app).

    Why do you say it must be synchronous? You didn't mention any functional requirements requiring that and I explained why such a design would make your ERP system worse.

  • Rana Anees Profile Picture
    1,813 on at

    Following is the x++ code provided by SMS service provider company that reference toy their API URL. I have created an account on their website.

    I have tested it in a job and its working fine. It returns a confirmation code from 1 to 14 once job i executed. Where 1 means success. I can also see sent messages history on their website.  
    Now I want to call it when sales order invoice is created, what is the name of class and method where so invoice is created. Here I will get Customer contact number and send the SMS.

    I want to do one more thing, I will create a table to same the returned SMS status code along with, Customer ID, SO ID, Invoice Id etc.

    static void SMS_Test(Args _args)
    {
        System.Net.WebClient custWebclient;
        System.IO.Stream InfoData;
        System.IO.StreamReader Streamreader;
        System.String URLStr;
        Str SMSConfirmID;
        str MobilyUserName = '966555555503';
        str MobilyPassword = 'pass123';
        str mobileno = '96644444444';
        str SenderName = 'CompanyName';
        str MessageText = 'This is a test SMS from AX to customer';
        try
        {
            custWebclient=new System.Net.WebClient();
            URLStr = "www.smsprovidercompany.ws/.../msgSend.php"+MobilyUserName+"&password="+MobilyPassword+"&numbers="+mobileno+"&sender="+SenderName+"&msg="+ MessageText +"&applicationType=60&lang=2";
            InfoData=custWebclient.OpenRead(URLStr);
            Streamreader=new System.IO.StreamReader(InfoData);
            SMSConfirmID=Streamreader.ReadToEnd();
            InfoData.Close();
            Streamreader.Close();
    
            info(strFmt("SMS Confirmation: %1", SMSConfirmID));
        }
        catch (Exception::Error)
        {
            info("Some Error");
        }
    
    }


    Thanks,

  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Sales invoice posting is done in SalesInvoiceJournalPost class.

    Let me explain once more why calling the web service synchronously would be a very bad design.

    Imagine that calling the service takes two seconds. If you do the call synchronously, every single posting will be delayed by two seconds, which wouldn't be a good news for users and customers, and potential locks in database would be held for extra two seconds, which could decrease performance of other processes as well.

    And now imagine that the SMS service is down completely. You'll get an error and the whole posing will fail, so your client may end up losing money because customers won't be able to complete their orders, for example (depending on actual business processes).

    If you want a separate table, a good approach would be writing a message to this table (with Invoice ID etc.) and having a periodic process that reads unsent messages, calls the service and updates status codes. Not only you'd avoid the problems mentioned above, but it would automatically support re-sending of failed messages.

    If you want to trigger sending immediately on posting, you still shouldn't do it synchronously. Utilize SysOperation framework to implement the logic and then use on of asynchronous execution modes.

  • Verified answer
    Rana Anees Profile Picture
    1,813 on at

    Got it. I wrote above code in class SalesFormLetter -> main() method.  

    custInvoiceJour = outputContract.parmJournal() available here and gives me SalesId, InvoiceID and customer detail.

    It is sending SMS to customers after the SO invoice is created.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans