Showing posts with label AIF AX 2012. Show all posts
Showing posts with label AIF AX 2012. Show all posts

Tuesday, 8 November 2016

Query Service AIF AX2012


 AIF query service can be used to fetch ad hoc data from AX2012 without creating a new service.
Its a common service which can be used to retrieve the data from AX database. There are three types of queries that you can run through a query service but I am discussing only the first two options here:


In the below code I will demonstrate the use of query service for fetching all the records from the SalesTable through the user defined query. In order to run this snippet, please make sure that AIF services are deployed and you are able to access the query service.  URI for the query service WSDL is:

http://<AOS_HOST>:8101/DynamicsAx/Services/QueryService


C# code for fetching the records

QueryServiceClient client = new QueryServiceClient();
QueryMetadata queryMetaData = new QueryMetadata();
queryMetaData.DataSources = new QueryDataSourceMetadata[] {
new QueryDataSourceMetadata() { DynamicFieldList=true, Table=”StudentTable”,  Name=”StudentTable”,  Enabled=true}
};

Paging paging = null;

DataSet ds = client.ExecuteQuery(queryMetaData, ref paging);

foreach (DataRow dr in ds.Tables[0].Rows)
{
Console.WriteLine(dr[“PersonnelNumber”].ToString());
}

Console.ReadLine();


Monday, 24 October 2016

Code to trigger outbound service AX AF 2012

We often get the requirement to export the the xml file for a particular document using outbound port. Outbound port can be triggered normally through AIF gateway classes in batch. Further their are requirements where we may need to generate the XML  using outbound port on any particular event.

Below is the code which can be placed on any event handler to trigger a outbound port configured for the XML document.

Sample X ++ code:

public client server static void OutboundFileSytemAdapterInvokeJob(XppPrePostArgs _args)
{
  SalesTable              salesTable;
  AxdSendContext          axdSendContext = AxdSendContext::construct();
  Map                     keyData;
  ClassId                 serviceClass;
  AifConstraint           aifConstraint = new AifConstraint();
  AifConstraintList       aifConstraintList = new AifConstraintList();
  AifActionId             actionId;
  AifEndpointList         endpointList;
 
  AIFGatewaySendService   aIFGatewaySendService = new AIFGatewaySendService();
  AifEntityKey            aifEntityKey  = AifEntityKey::construct();
  #define.xmlServiceRead('SalesSalesOrderService.read')
 
 
     
  salesTable= _args.getThis();
 
  if(salesTable.RecId)
  {
   keyData = SysDictTable::getKeyData(salesTable);
   aifEntityKey.parmTableId(salesTable.TableId);
   aifEntityKey.parmRecId(salesTable.RecId);
   aifEntityKey.parmKeyDataMap(keyData);
   axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
   axdSendContext.parmSecurity(false);
   serviceClass = className2Id(classStr(SalesSalesOrderService));
   aifConstraint.parmType(AifConstraintType::NoConstraint);
   aifConstraintList.addConstraint(aifConstraint);
   if(serviceClass)
   {
    //Get the actionId of the default action for this document class
    actionId = AifSendService::getDefaultSendAction(serviceClass, AifSendActionType::SendByKey);
    actionId =  xmlServiceRead;
 
    if(actionId)
    {
     //Get the list of valid Endpoints
     endpointList = AifSendService::getEligibleEndpoints(actionId, aifConstraintList);
     AifSendService::submit(actionId,endpointList,aifEntityKey,AifSendMode::Sync,axdSendContext.pack(),AifProcessingMode::Parallel);
    }
   }
   AIFGatewaySendService.run();}
 }
}