Home > X++ stuffs > AIF Find/Read Service Class in Dynamics AX

AIF Find/Read Service Class in Dynamics AX

 

In continuance to my existing article about AIF Service classes in Dynamics AX. Here is the sample class by which we can read/find the data from a table and publish it using AIF Service.

static void ExpenseReadOutbound()

{

    AifEntityKey           entityKey     = new AifEntityKey();

    AifEntityKeyList      entityKeyList = new AifEntityKeyList();

    TrvExpTable           trvExpTable;

    TrvExpenseService  expenseService;

    AifDocumentXml     documentXml;

    XmlDocument         xmlDoc;

    Random                  objRandom = new Random();

    ;

 

    expenseService = TrvExpenseService::construct();

 

    //Record Selected to pass to entityKey which is ‘Not Like’ in X++ SQL statement.

    while select trvExpTable

        where !(trvExpTable.PostStatus like TrvPostStatus::Transferred)

    {

        entityKey.parmKeyDataMap(SysDictTable::getKeyData(TrvExpTable));

        entityKeyList.addEntityKey(entityKey);

 

        try

        {

            documentXml = expenseService.read(entityKeyList).serialize();

 

            //Initialize xMLDocument only after the entity key list of the entities reads.

            xmlDoc      = new XmlDocument();

            xmlDoc.loadXml(documentXml);

            xmlDoc.save(@"C:\Expense" + int2str(objRandom.nextInt()) + ".xml");

        }

        catch

        {

            exceptionTextFallThrough();

        }

    }

}

static void ExpenseFindOutbound()

{

    TrvExpenseService expenseService;

    AifDocumentXml    documentXml;

    XmlDocument        xmlDoc;

    AifQueryCriteria    queryCriteria;

    Random                objRandom = new Random();

    AifCriteriaElement criteriaElement;

    ;

 

    expenseService = TrvExpenseService::construct();

    queryCriteria    = AifQueryCriteria::construct();

 

    criteriaElement = AifCriteriaElement::newCriteriaElement(tablestr(TrvExpTable),

                                                                                          fieldstr(TrvExpTable, ExpNumber),

                                                                                          AifCriteriaOperator::Greater,

                                                                                          ‘TRV-000005’);

 

    queryCriteria.addCriteriaElement(criteriaElement);

 

    try

    {

        documentXml = expenseService.find(queryCriteria).serialize();

 

        //Initialize xMLDocument only after the find entities matching a criteria.

        xmlDoc      = new XmlDocument();

        xmlDoc.loadXml(documentXml);

        xmlDoc.save(@"C:\Expense" + int2str(objRandom.nextInt()) + ".xml");

    }

    catch

    {

        exceptionTextFallThrough();

    }

}

Yahooooooo…..I just love aX iNTegraTion fRameWoRk Smile 

Alternatively you can also download the sample code from the below link

http://cid-264a0056cbcbb1d3.skydrive.live.com/self.aspx/.Public/Job%5E_ExpenseFindOutbound.xpo

http://cid-264a0056cbcbb1d3.skydrive.live.com/self.aspx/.Public/Job%5E_ExpenseReadOutbound.xpo

Advertisements
Categories: X++ stuffs
  1. vjiway
    December 21, 2010 at 12:41 pm

    Hi Santosh,

    I need to get a update response message back from Ax if a particular record is updated in Ax.Presently it is not there in Ax.So can we have a workaround for this.
    If there is a fault while updating a record it sends a message back,but if it is a successful update it should at least give a particular response.

    • December 21, 2010 at 5:17 pm

      Hey,

      You can try to put your update response message in validateWrite() method in AX. Since when any record is updated then validateWrite() will be called. So you can send a Response message stating “This particular record is updated” along with the updation details.
      (For getting the updation details pls store the previous values in orig and then compare and send across)

      You can achieve the fault message if records are not updated using try-catch statement.

      Please feel to try this 🙂 and let me know.

  2. vjiway
    December 21, 2010 at 12:39 pm

    Hi Santosh,

  3. November 3, 2010 at 11:56 pm

    Hi Santosh

    Thanks for sharing X++ Stuffs.

    I’m implemting ‘Ax2009-External System’ data exchange through AIF. I would like to Send/Receive XML messages To/From A FTP folder (coz its remote)

    Could you please let me know how to do that?

    Thanks
    Zafa

    • November 9, 2010 at 10:21 am

      Hi,

      Thanks for visiting my blog :). You can send/Receive XML message using FTP folder.

      You may be interested in looking into the following blog where my friend has illustrated how to work on AIF with FTP
      http://sumit-theaxfactor.spaces.live.com/blog/cns!596957786228C73F!274.entry

      Thanks
      Santosh.R

      • November 10, 2010 at 11:47 pm

        I read it. Thanks.

        Change in req. I’m in the process implementing AIF with Webservice

        1. Posting XML to external web service
        2. Should the AIF webservices installed in our DEV AOS server?
        3. Is it possible to access AIF services installed in different server from our DEV server?

        Im clueless. can you help me….?

        Thanks
        Zafa

      • November 11, 2010 at 1:50 pm

        Zafa,

        Please find the inline comments for the posted query
        2) Should the AIF webservices installed in our DEV AOS server?
        Ans: This is a prerequiste which is required to use AIF webservice in DEV AOS Server.

        3. Is it possible to access AIF services installed in different server from our DEV server?
        Ans: Its possible to access the webservice via AIF services only if it belong the current AOS.

        Could you be more specific to question no:1???

        Thanks
        Santosh.R

      • November 15, 2010 at 8:25 pm

        Thanks for your prompt response.

        Basically my requirement is passing Sales Order / Transfer Order information to an external Warehouse Mgmt system (WMS) when the user manually trigger the orders.

        1. When the user manually trigger (Post) the order, it has to post (Push) the XML into the destination WebService.

        2. When the WMS receives the order, we have to get (Pull) the info and update our DAX EPR system.

        Could you please assist me how to acheive this?

        I understand i have to configure AIF Web Service for these actions? Need help on this.

        Thanks
        Zafar

      • November 17, 2010 at 2:31 pm

        Zafar,

        For the outbound webservice requirement you can follow David suggestion which is put up on his blog..

        http://blogs.msdn.com/b/dpokluda/archive/2006/10/03/outbound-web-service-_2800_aif_2900_.aspx

        For inbound webservice please refer santosh blog.

        http://paruvellas.wordpress.com/2008/07/30/dynamics-ax-aif-web-service-for-axdsalesorder/

        In case if still have queries please revert back.

      • November 19, 2010 at 1:45 am

        Thanks for your response Santosh…

        Do you know how to POST my sales order / transfer order information to an external website through HTTP POSTING from X++?

        I’m sorry that i have jumped from WebService to HTTP Posting. But this seems to be the requirement.

        I have read somewhere that we can do it through System.Net.HttpWebRequest & System.Net.HttpWebResponse classes from X++?

        Do you know how to achieve this. would appreciate if you pointed out a code example…?

  4. Anitha
    February 17, 2010 at 5:20 pm

    Mr.AIF !!!Thanks for sharing this info..

  1. October 11, 2010 at 3:45 pm

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: