Search This Blog

Monday, February 20, 2012

AX2012 Consume DocumentServices using .Net

Call Vendor service to create vendor in AX.
Create ConsoleApplication  in .net evironment and add the servicereference vendVendTableService, and write the following code.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication9.Vendors;
namespace krishh_VendTableIntegration
{
    class VendServiceIntegration
    {
        static void Main(string[] args)
        {
            VendTableServiceClient vendClient= new VendTableServiceClient();
            CallContext context = new CallContext();
            context.Company = "CEE";  
            AxdVendTable vendor = new AxdVendTable();
             AxdEntity_VendTable[] vendTables = new AxdEntity_VendTable[1];
            AxdEntity_VendTable vendTable = new AxdEntity_VendTable();
          //If your number sequences for vendor accounts are set to manual set this property           
            //vendTable.AccountNum = "30001"; 
         // make sure this currency must be available in your currencies list
          vendTable.Currency = "DKK";      
        // make sure this vendgroup must be available in you master vendgroup    
          vendTable.VendGroup = "10";
          
          vendTable.Name = "www.captivatesolutions.com";
           //Create the party record
           AxdEntity_DirPartyTable_DirPerson party = new AxdEntity_DirPartyTable_DirPerson();
          party.NameAlias = "Krishna";
          //Set the name fields
          AxdEntity_PersonName personName = new AxdEntity_PersonName();
         personName.FirstName = "Krishna";
        personName.MiddleName = "Reddy";
        personName.LastName = "Mod";
      //Add the PersonName Enrtity to the party record and set the name sequence
       party.PersonName = new AxdEntity_PersonName[1] { personName };
      // this sequence will set you name display order
     party.NameSequence = "FirstLast";           
    // add the dirparty to the vendor
    vendTable.DirPartyTable = new AxdEntity_DirPartyTable_DirPartyTable[1] { party };
   vendTables[0] = vendTable;
   vendor.VendTable = vendTables;
  vendClient .create(context, vendor);
        }
    }
}
Same way we can integrate customer as well.

7 comments:

  1. How to use a service to Create record in Ax through X++ code.
    I had created service i would like to know which class i should use create a record.

    ReplyDelete
    Replies
    1. Hi,
      If you develop a service for that Service you will define the class which will have all the functionalities to create,find,read,update.
      If you want to use that service,Deploy the service and it will create the class with the postfix as client with your servicenameclass. that class you have to initialize and use the class..

      so you client class will act as a proxy class.

      I hope you understand...how to use it now.

      if its not clarified let me know.

      regards,
      krishna.
      krishna.dynamics@gmail.com

      Delete
  2. I have class which has parmName,etc table field
    i had instantianted used that to inserted data.

    another classService which has create,delete,read
    how do i use this ?

    axdclass how do i use it ?

    another class which has createtablename
    parmtablename which takes stronglytypedcontainerlist as variable;

    axclass


    can you explain show an example.

    ReplyDelete
    Replies
    1. Take an Example of VendVendTableService
      VendTable-AxVendTable(For every table there will be AXTablename when you have a service)
      So when you created a service for that table it will created the class name as ax which extends from AXInternalBase where this class contains all the parmMethods and Exist Methods.

      AxdVendTable- this class contains the PrepareforSave,Extendend and updatenow. if you want to change the values and if you want to assign some default values you can assign in this methods based on your requirement.
      This class extends from AXDBase class.

      VendVendTableService:- this class contains all the methods that you want to expose like create,Update,Read, find.

      After building the service class you have create one service group where you have to add this service into that group and deploy it.

      If you want to see the Example how to use it...you can see my earlier post in my blog as following link.

      http://krishhdax.blogspot.com/2012/03/ax2012-import-vendors-from-csv-using.html


      This explanation will help you to use the service classes.

      Delete
  3. can you provide the code to update Vendor information based on vendor using the Update service operation here

    Vaibhav

    ReplyDelete
  4. Hi can you please provide me some information or code snippet to insert free text invoice using cust free text invoice service.
    Thanks
    Daws

    ReplyDelete
  5. hi, could u plz post code for update..

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.