RSS

Category Archives: AIF

AIF–handling related incoming records


I had to being able to handle HRM applicants and applications from a corparate website. In basics the customer wanted to have a webform where the applicant could enter his/her personal data and attach files like eg. a CV, the application or any other relevant stuff.

To handle that scenario I created two tables in AX – one to handle the applicant and application related stuff and another to handle the file attachments. One application should be able to have many attachments. Therefore the first attachment should relate to one application and the second attachment to the same application and so on…

Having the datamodel set, I created a document service.

I created a simple webform in c# that consumed the AIF service and I was soon able to send data into AX. Then it occured to me, that I wasn’t able to create the relation between attachments and applications from the webclient because I needed the RecID og the Application in order to put in onto the attachments.

Inside ax i found the PrepareForSaveExtended method of my AXD class to be useful. Here I could make sure that applications would be processed before attachments. And once the applications were processed I could fetch the RecId and put in on each attachment.

I ended up with this:

Class declaration:

 

class Axdegf_HRMWebRecruitment extends AxdBase

{

#define.WebRecruitment_DataSourceName(‘WebRecruitment’)

#define.Attachments_DataSourceName(‘Attachments’)

 

 

HRMWebRecruitment            axbc_WebRecruitment;

HRMWebRecruitmentAttachments axbc_Attachments;

 

}

PrepareForSaveExtended:

public boolean prepareForSaveExtended(

AxdStack                    _axBcStack,

str                         _dataSourceName,

AxdRecordProcessingContext  _recordProcessingContext,

AxInternalBase              _childRecord)

{

//TODO: Add code here to ensure that required fields specified in the initMandatoryFieldsMap method are sent in by the service caller.

switch (_dataSourceName)

{

// ———————————————————————-

// Process WebRecruitment records

// ———————————————————————-

case #WebRecruitment_DataSourceName:

 

axbc_WebRecruitment = _axBcStack.top();

switch (_recordProcessingContext)

{

 

case AxdRecordProcessingContext::BeforeChildRecordProcessed:

switch(_childRecord.dataSourceName())

{

case #Attachments_DataSourceName:

if(!axbc_WebRecruitment.isProcessed())

{

return true;

}

break;

}

return false;

 

// Ensure WebRecruitment record is saved

case AxdRecordProcessingContext::AfterAllChildRecordsProcessed:

if (!axbc_WebRecruitment.isProcessed())

{

return true;

}

return false;

}

return false;

// ———————————————————————-

// Process Attachments records

// ———————————————————————-

case #Attachments_DataSourceName:

 

axbc_Attachments = _axBcStack.top();

//axbc_Attachments.parmDescription(“dudelidut”);

switch (_recordProcessingContext)

{

 

// Propagate parent’s key

case AxdRecordProcessingContext::BeforeAnyChildRecordsProcessed:

axbc_WebRecruitment = axbc_Attachments.parentAxBC();

axbc_Attachments.parmHRMWebRecruitmentRecIdRef(axbc_WebRecruitment.currentRecord().RecId);

return false;

 

// Ensure Attachments record is saved

case AxdRecordProcessingContext::AfterAllChildRecordsProcessed:

if (!axbc_Attachments.isProcessed())

{

 

return true;

}

 

return false;

}

return false;

 

// ———————————————————————-

// Unsupported data sources

// ———————————————————————-

default:

error(strfmt(“@SYS88979”,classId2Name(classidget(_axBcStack.top()))));

return false;

}

return false;

}

 

Advertisements
 
Leave a comment

Posted by on July 29, 2016 in AIF, Uncategorized

 

AIF–duplicate types with name Dynamics.Ax.Application…


I had to redeploy an AIF http document service several times due to changes. Ocassionally the below error would occur when opening the inbound ports form. The error indicated that the classes related to my document service somehow would conflict because they were already registered. In the current state it would not be possible to activate a new inbound port.

DuplicateType

Fortunateley a colleague of mine had experienced something similar and here is our guide that in the end solved my issue:

  • Create a job that deletes everything  from the SysXppAssembly

static void Job1(Args _args)
{
SysXppAssembly sysxppassembly;
ttsBegin;
delete_from SysXppAssembly;
ttsCommit;
}

  • Stop the AOS.
  • Delete all files (and folders) from the “C:\Program Files\Microsoft Dynamics AX\60\Server\[instancename]\bin\XppIL” folder
  • Start the AOS and go to Systemadministration/setup/services and application integration framework/inbound ports to check if the error has gone.

In most cases that would solve the problem. In one situation I experienced that the above gude was not enough. I also had to do the following:

  • compile the entire application
  • Perform full CIL
  • Restart the AOS
Reference :https://philippsen.wordpress.com/2015/05/11/aifduplicate-types-with-name-dynamics-ax-application/
 
Leave a comment

Posted by on July 29, 2016 in AIF, Uncategorized

 

Generating the outbound xml file for all records using File system adapater in ax 2012 AIF


  1. Generating the outbound xml file for selected record or single record – using document service(file system adapter).
  2. Generating the outbound xml file for all records( i.e. specified criteria on the query) – using document service(file system adapter).

    Example: Generating the outbound xml file for selected record or single record.
    Below is the code to generate the outbound xml file for the selected record.
    static void GenerateXmlSelectedRecord(Args _args)
    {
    AxdSendContext      axdSendContext  = AxdSendContext::construct();
    AifEntityKey        aifEntityKey    = AifEntityKey::construct();
    AifEntityKeyList    aifEntityKeyList = AifEntityKeyList::construct();
    Map                 keyData;
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    CustTable           custTable;
    int i,j;
    CustCustomerService CustCustomerService = CustCustomerService::construct();
    ;
    custTable = CustTable::find(‘Cust001’);

    keyData = SysDictTable::getKeyData(custTable);
    aifEntityKey.parmTableId(custTable.TableId);
    aifEntityKey.parmRecId(custTable.RecId);
    aifEntityKey.parmKeyDataMap(keyData);

    aifEntityKeyList.addEntityKey(aifEntityKey);

    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);

    aifConstraint.parmType(AifConstraintType::NoConstraint) ;
    aifConstraintList.addConstraint(aifConstraint) ;

    info(strFmt(“%1”,custTable.AccountNum));
    AifSendService::SubmitDefault(  classnum(CustCustomerService),
    aifEntityKey,
    aifConstraintList,
    AifSendMode::Async,
    axdSendContext.pack());
    }

    Example: Generating the outbound xml file for all records( i.e. specified criteria on the query).
    Below is the code to generate the outbound xml for all the records or specified criteria.

    static void GenerateMutiplerecords(Args _args)
    {
    CustTable           custTable;
    AxdSendContext      axdSendContext      = AxdSendContext::construct();
    AifEntityKey        aifEntityKey        = AifEntityKey::construct();
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    AifEndpointList     endpointList;
    AifActionId         actionId;
    Query               query;
    QueryBuildDataSource    qbds;

    query               = new Query(queryStr(AxdCustomer));
    AxdSend::removeChildDs(query);

    actionId            = AifSendService::getDefaultSendAction(classnum(CustCustomerService), AifSendActionType::SendByQuery);
    aifConstraint.parmType(AifConstraintType::NoConstraint);
    aifConstraintList.addConstraint(aifConstraint) ;
    endpointList        = AifSendService::getEligibleEndpoints(actionId, aifConstraintList);

    AifSendService::SubmitFromQuery(actionId,endpointList,query,AifSendMode::Async);
    }

https://msdn.microsoft.com/en-us/library/aa859008.aspx

 
Leave a comment

Posted by on May 26, 2015 in AIF

 

Tags:

AIF Service Common Usage Scenarios in ax 2012


Custom Services: Use to expose very simple business entities as a service, or to expose custom logic from Microsoft Dynamics AX.

This Service enables developers to expose any logic written in x++ through a service interface. The support for Custom Services was introduced in Dynamics AX 2009, but it was limited to some specific data types. In Microsoft Dynamics AX 2012 with the integration of Windows Communication Foundation (WCF), attributes can be set on the Data Contract class to make them serialize and De-serialize across the network connection.

  • To expose a custom x++ logic.
  • Say, you have a custom module and you want to expose some logic/code to your custom application.

Document Services: – Use to expose business entitles with varying degrees of complexity, or to support medium-to-complex integration scenario involving business entities.

This was introduced in Microsoft Dynamics AX 4.0. It enables the user to exchange data between internal and external systems via XML documents. Document Services are generated from a query that models the business entity. For example, a customer query will run the Document Service Generation Wizard to create the Service artifacts.

Document Services include logic to handle the details of how a query will be serialized or De-serialized from the XML that is sent across a network. For synchronization of Document Services, there are two new entities introduced in Dynamics AX.

  • getKey
  • getChangedKey

Developers need to extend these functions to enable their own scenario.

  • Document services are services which expose a business entity. For example, Customer, Vendor, Employee, Sales Order.
  • You can Map the business entity using Query and run through Document Service Wizard to build the web service and perform CRUD operations.

System Service: System services are Windows Communication Foundation (WCF) services that are included with Microsoft Dynamics AX. These services enable clients to interact with and retrieve system information.

This is a new Service category introduced in Microsoft Dynamics AX 2012. This type of Service is not customizable and not mapped to any X++ code. There are three types of Services that come under System Services:

  • Query Service
  • Metadata Service
  • User Session Service

All these Services have unique functionality that will be discussed in my next post.

  • System services are kind of utility services.
  • Up and running when AOS starts.
  • Can be used for interactive clients
  • Build Ad-hoc query

System Service: Query Service: – Use to implement read operations for any Microsoft Dynamics AX, ad-hoc, or existing AOT query.

  • Enables you to issue a query for data without using an Application Integration Framework (AIF) document service or creating a custom service. The query service returns data in a dataset and implements a paging mechanism so that you can manage queries that return large amounts of data.

When you call the query service, you can specify the query to run in one of three different ways:

    • Static query – A query that is already defined in the AOT under the Queries node.
    • User-defined query – A query that is defined by using the QueryMetadata class which is found in the metadata service.
    • Dynamic query – A query that is defined in an X++ class that extends the AifQueryBuilder class. All query logic resides in the query builder class

System Service: Metadata Service: – Use to retrieve information about the structures in Microsoft Dynamics AX for a client application. For example, if you want to return information about a table such as what indexes exist on that table, you can use the metadata service.

Enables you to retrieve information about elements in the AOT. You can retrieve metadata for labels, menus, menu items, tables, extended data types, data types, enums, queries, web menus, web menu items, info parts, cues, dimensions, form parts, web controls, service groups, and services. The metadata service should be used when you want to return information about the structures in Microsoft Dynamics AX to a client application. For example, if you want to return information about a table such as what indexes exist on that table, you can use the metadata service.

System Service: User Session Service: – Use to retrieve information about the user session.

Enables you to return information about the current Windows user. You can return information such as the user’s default language, Default Company, default company time zone, permissions to access-controlled items, and so on

 
Leave a comment

Posted by on May 25, 2015 in AIF

 

Tags:

AX Data Export in XML file



static void XMLExport(Args _args)
{
    XmlDocument doc;
    XmlElement  nodeXml;
    XmlElement  nodeTable;
    XmlElement  nodeAccount;
    XmlElement  nodeName;
     XmlElement  nodeItemName;
    XmlElement  nodeModelGroup;
    XmlElement  nodeDimGroup;
    InventTable inventTable;
    #define.filename(‘C:\\Users\\varun.garg\\Desktop\\test.xml’)
    ;
    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement(‘xml’);
        doc.appendChild(nodeXml);
    while select inventTable
    {
        nodeTable = doc.createElement(tablestr(InventTable));
        nodeTable.setAttribute(
            fieldstr(InventTable, RecId),
            int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(
            fieldstr(InventTable, ItemId));
        nodeAccount.appendChild(
            doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(
            fieldstr(InventTable, ItemGroupId));
        nodeName.appendChild(
            doc.createTextNode(inventTable.ItemGroupId));
        nodeTable.appendChild(nodeName);
         nodeItemName = doc.createElement(
            fieldstr(InventTable, ItemName));
        nodeItemName.appendChild(
            doc.createTextNode(inventTable.itemName));
        nodeTable.appendChild(nodeItemName);
        nodeModelGroup = doc.createElement(
            fieldstr(InventTable, ModelGroupId));
        nodeModelGroup.appendChild(
            doc.createTextNode(inventTable.ModelGroupId));
        nodeTable.appendChild(nodeModelGroup);
        nodeDimGroup = doc.createElement(
            fieldstr(InventTable, DimGroupId));
        nodeDimGroup.appendChild(
            doc.createTextNode(inventTable.DimGroupId));
        nodeTable.appendChild(nodeDimGroup);
    }
    doc.save(#filename);
}

 
Leave a comment

Posted by on July 26, 2011 in AIF, X++

 

Tags:

 
All About Dynamics 365

Dynamics 365, D365, Implementor

Syed Rafay Ali

This blog contains information about Functional techniques and guidelines in Microsoft Dynamics AX, including tips, tricks, tutorials, tools and upcoming news enhancement in Microsoft Dynamics Ax

Philippsen's Blog

Everyday findings in my world of .net and related stuff

Microsoft Dynamics AX

A great WordPress.com site

Finite Minds

Adventures in IoT

Dynamics Ax

Technical Knowledge

timsaxblog

A blog about implementing Microsoft Dynamics AX and Dynamics 365 for Operations

Microsoft Dynamics 365 Blog

"Learn it all, not Know it all" in Dynamics 365 - Enterprise Edition, A Blog by Sandeep Chaudhury

DEVSerra - Dynamics AX development blog

Your official Microsoft Dynamics AX blog.

OrganicAX

Discovering Dynamics

AX

A blog by Hai Nguyen

Learn Dynamics Ax with Johnkrish

Live as if you were to die tomorrow. Learn as if you were to live forever - Mahatma Gandhi ****** The more I learn, the less I know - Albert Einstein

Twisted Untwirled

Just another WordPress.com site

ramdynamicsax

Just another WordPress.com site

guyterry's Dynamics AX blog

Just another Dynamics AX blog