Saturday, December 3, 2016

Import Data From XML Through DIXF-AX 2012

l.png

Microsoft Dynamics AX 2012 Data Import/Export Framework provide the functionality to import data from an XML data source into Dynamics AX Open AX then Go To DIXF > Setup > Source data format >
  •  Click New
1
  Data Import Export framework–>Setup–>Target entities Create New , as like below  image 2 Go To Common > Processing group > Click new enter the Processing group Name, Description > Click Ctrl + S to save > Click Entities. Enter Group name =CustGroup-XML-2 , Description="Import data from XML" and save -->click on Entities 3
 select entity name = Custgoup Source data format=XML-2 4 click on Generate Source File select XML type= XML Generate Sample File and save this file to "DataMigrations" folder and enter sample data 5.png 12.png
 Click on Modify Source Mapping and map source and target fields as like and save Browse and



select file tGroup.xml

  6.png

Click on Generate Source file then Click Validate ---> then Click Preview Source File 7.png Now  Go To processing Group and select Group name and click on Get staging data 8.png
Click on Run --> then click Ok

9.png

 Then give message "record inserted in target table"


  10.png

for cross checking you goto Account receivable -->setup-->Customer-->Customer groups and view
Customer Group successfully inserted



  11.png

Friday, November 18, 2016

Purchase order , Application Integration Framework (AIF) service with Microsoft Dynamics AX 2012



Retrieving purchase order from Microsoft Dynamics AX 2012 with help of custom Application Integration Framework (AIF) service

(1) Create a new class – first we will create a new class in AX which will contain the service operations

(2) open AOT. Go to Classes and create a new class. 

 Name=Test_PurchOrderService, and  set the RunOn property of the class to Server.



(3) Add a new method and name it as getPurchOrderList

[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return',Types::String)]
public List getpurchaseorderlist()
{
    PurchTable purchtable;
    List list=new List(Types::String);
    while select * from purchtable
    {
        list.addEnd(purchtable.PurchId);
    }
    return list;
}



(4) Create a new service 
Name- PurchOrderService, property of class -Test_PurchOrderService

Open the properties of the newly created service and select the PurchOrderService class in the Class field.


(5) Now expand the PurchOrderService service node and add a new Operation by right clicking on Operations and selecting Add Operation.


(6) Create a new service group – the next step is to create a service group and deploy the service to the Inbound Port

Go to Service Groups, right click and select New Service group, and Name it as PurchOrderServiceGroup.


(7) Set the AutoDeploy to Yes and set the Description as Purchase Order Service

(8) Drag and drop PurchOrderService to PurchOrderServiceGroup

(9)Now right click the service group and select Deploy Service Group.

(10) Verify the service

(11) go to System administration > Setup > Services and Application Integration Framework > Inbound ports


(12) The WSDL URI is the URL of the service which can be used by external systems to access the service.


Consume the service

In Visual Studio, create a new project of type Windows Form Application and name it TestPurchOrderService.

(12) File-- New Project-->Visual C#-->Windows Form Application -- Name of Project(TestPurchorderService)

(13) In Solution Explorer, expand the node for your project. Right-click the References node, and then click Add Service Reference.



http://HOME:8101/DynamicsAx/Services/PurchOrderServiceGroup

(14) Click Go.

The form becomes populated with a node for your service. Click the option button for your service.


(15) Click OK, and the service reference will be added as below.


  1. Now we are now ready to use the proxy classes in our program.
  2. Run the form – open the form and add a button and a list box control to the form.
(16) Add the below code to the Get Purchase Order List button click event:


(17) below code write in button click

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TestPurchOrderService.PurchOrderServiceRef;
namespace TestPurchOrderService
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] purchorderlist;
            try
            {
                PurchOrderServiceRef.CallContext callcontext = new PurchOrderServiceRef.CallContext();

                    // StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();
                PurchOrderServiceRef.PurchOrderServiceClient client = new PurchOrderServiceRef.PurchOrderServiceClient();
                callcontext.Company = "ceu";
           // StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();
                purchorderlist = client.getpurchaseorderlist(callcontext);
                for (int i = 0; i < purchorderlist.Length; i++)
                {
                    listBox1.Items.Add("Line" + i.ToString() + ":Purchase order Number " + purchorderlist[i].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
    }
}


(18) Click Get Purchase Order List button and the output will be like below:



Thursday, June 2, 2016

AX 2012: Create Custom Workflow


I have Student Fee Collection Table and School Administration wants Approval Process,
If fee is pending then they are not allow for next semester etc.

Base Enums
(1) Create “CustFreeInvoiceWFApprovalStatus”  base enums for the workflow approval status



Create “FStatus”  base enums for the workflow approval status


(2) Create New Table “studenttable”

Field
Datatype
Id
Integer
Name
String
Fee
Real, Extended Datatype= AmountMST
FStatus
Enum, Enum Type= FStatus
WorkflowStatus
Enum,Enum Type= CustFreeInvoiceWFApprovalStatus

Override Method on "studenttable" Table
Override canSubmitToWorkflow method on studenttable

public boolean canSubmitToWorkflow(str _workflowType = '')
{
 
    boolean ret;
 
   if(this.FStatus==FStatus::Inreview)
    {
        ret=true;
    }

    return ret;}

(3) Create Query “studentQuery”


(4) Create simple list form “StudentForm


(6) Create New Menu Itemà Displayà Studentmenu



(7) Workflow Category:

AOTàworkflowàWorkflow Categoiesàcreate new “StudentWFCategory


(8)Workflow Type: “studentwft”

AOT-->Workflow-->Workflow type-->Right Click-->Add-Ins-->WorkFlow type Wizard-->Next

This will create a private project ,
After the workflow type is created, add code for the workflow events.

 Add below code to the studentwftSubmitManager class on workflow type project

(9)Create one method “Submit”

void submit(Args args)
{
// Variable declaration.
recId recId = args.record().RecId;
WorkflowCorrelationId workflowCorrelationId;
// Hardcoded type name
WorkflowTypeName workflowTypeName =workflowtypestr("studentwft");
// Initial note is the information that users enter when they
// submit the document for workflow.
WorkflowComment note ="";
WorkflowSubmitDialog workflowSubmitDialog;
    studenttable stable;
//CustInvoiceLine custInvoiceLine;
// Opens the submit to workflow dialog.
workflowSubmitDialog =WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
recId = args.record().RecId;
stable = args.record();
// Get comments from the submit to workflow dialog.
note = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
workflowCorrelationId =Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Submitted;
// Send an Infolog message.
info("Submitted to workflow.");
ttscommit;
}
catch(exception::Error)
{
info("Error on workflow activation.");
}
}
args.caller().updateWorkFlowControls();

(10) Goto “main” method of class

public static void main(Args args)
{
   studentwftSubmitManager  SubmitManager =new studentwftSubmitManager();
    SubmitManager.submit(args);
}


(11) Update code on studentwftEventHandler class for different events

Add below code on completed method

public void completed(WorkflowEventArgs _workflowEventArgs)
{
   studenttable stable;
    RecId SRecId;
   SRecId =_workflowEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Completed;
    stable.FStatus=FStatus::Approve;
    stable.update();
    ttsCommit;
}

Add below code on started method

public void started(WorkflowEventArgs _workflowEventArgs)
{
    studenttable stable;
    RecId SRecId;
   SRecId =_workflowEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Pending;
    stable.FStatus=FStatus::Pending;
    stable.update();
    ttsCommit;

}

Add below code on canceled method

public void canceled(WorkflowEventArgs _workflowEventArgs)
{
     studenttable stable;
    RecId SRecId;
   SRecId =_workflowEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Cancellation;
    stable.FStatus=FStatus::Cancel;
    stable.update();
    ttsCommit;
}

(12) Update Lables on Menuitems

studentwftSubmitMenuItemàproperties à set label as Submit-WFT
studentwftCancelMenuItemàpropertiesà set label as Cancel-WFT

***************************************************************************
(13) Enable workflow on form

Goto Form “StudentForm” -à Design->properties
Workflowenabled=Yes ,
workflowdatasource= studenttable
workflowtype= studentwft


(14) Workflow Approval:

Open the AOT.-->Expand the Workflow node.-->
Right-click on Approvals and select Add-ins > Approval wizard.
Click Next.

This wizard will create the private project as below:

(15) Now, Update code on studentApprovalEventHandler for different events

public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
    studenttable stable;
    RecId SRecId;
    SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Completed;
    stable.FStatus=FStatus::Approve;
    stable.update();
    ttsCommit;
}

public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{

    studenttable stable;
    RecId SRecId;
    SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Cancellation;
    //stable.FStatus=FStatus::Cancel
    stable.update();
    ttsCommit;}

 public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
    studenttable stable;
    RecId SRecId;
    SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::ChangeRequested;
    stable.update();
    ttsCommit;
}

public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
    studenttable stable;
    RecId SRecId;
    SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Rejected;
    stable.FStatus=FStatus::Cancel;
    stable.update();
    ttsCommit;
}

public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
   studenttable stable;
    RecId SRecId;
    SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::Rejected;
    stable.update();
    ttsCommit;
}

public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
    //WorkflowElementStartedEventHandler
    studenttable stable;
    RecId SRecId;
    SRecId=_workflowElementEventArgs.parmWorkflowContext().parmRecId();
    ttsBegin;
    select forUpdate stable where stable.RecId == SRecId;
    stable.WorkflowStatus =CustFreeInvoiceWFApprovalStatus::PendingApproval;
    stable.FStatus=FStatus::Pending;
    stable.update();
    ttsCommit;
}

(16) Update Lables on Menuitems

studentApprovalApprove set label as Approve
studentApprovalRejectset label as Reject
studentApprovalRequestChange set label as Request change
studentApprovalDeny  set label as ApprovalDeny

(17) Drag workflow approval to workflow type

Drag workflow approval “studentApproval” to workflow type under studentwft> Supported elements



(18)Create Menu for Menu itemàDisplayàStudentworkflow


(19)Drag and Drop Menu items  ” Studentworkflow”  in “Home” Menu


(20)Drag and Drop Menu items  ” Studentmenu”  in “Home” Menu


(21)Start Compile , AOT-->Right click--> incremental CIL compile 

(22)Open Work Flow: menu and student Form






Friday, May 27, 2016

Creating Base and Derived Tables,Table Inheritance in AX 2012

A table also can derive from another table.tables in AX 2012 have two new properties; (1) SupportInheritance property, and (2) the Extends property

one table is  base table, and the other is  derived table
When we use of inheritance between two tables.when all the following conditions are true:

  1. There is no thought that there might be a 1-to-many or many-to-many relationship between the two tables.
  2. An existing row in the proposed base table, and the corresponding row in the derived table, both refer to the same item in the real world.
  3. Each row in the proposed base table has exactly one corresponding row in the derived table.
  4. If one row is ever deleted from either table, the corresponding row must also be deleted.
  5. The base table probably has at least two tables that derive from it.
    1. The two derived tables have fields for different kinds of things.
    2. The two derived tables refer to different variations of the general items that are tracked together in the base table. 
  6. No item that is represented in a base table would ever be represented in more than one of its derived tables.
  7. The derived table is not meant for performance tuning of the physical database, such as placing an image column in its own table.
example of Variations to a Listing:=

Color,Fabric,Flavor,Height,Length,Material,Size,Style,Weight,Width

Example of different Kinds of things
fruit- apples, grapes, and pears
Animals:-amphibians,birds,fish,invertebrates,mammals,reptiles

A T-shirt might come in multiple colors and sizes

ID
Name
Brand
Size
Color
1
T-Shirts
L
Green  
2
T-Shirts
Nike
S
Blue  
3
Adidas
XL
Green  
4
T-Shirts
Lee  
S
White  


Step-1  Create a table called “Tshirt
Step-2  Set table property 'supportInheritance' to 'Yes'
Step-3  Create a filed name called 'InstanceRelationType' extends 'RelationType'
Step-4  Set table property 'InstanceRelationType' to 'InstanceRelationType'
Step-5  Create two filed called Id and Name,Brand as shown below screen



Step-6  Create another table called “Tabtshirtsize”
Step-7  Set table property 'supportInheritance' to 'Yes'
Step-8  Set table property 'Extends' to “Tshirt”

Step-9  Create filed called size as shown below screen


Step-10  Create another table called “Tabtshirtcolor”
Step-11 Set table property 'supportInheritance' to 'Yes'
Step-12  Set table property 'Extends' to “Tshirt”

Step-13 Create filed called size as shown below screen



we need to also set the ‘Abstract’ property of the parent table to ‘Yes’ 

Records can only be created for concrete table types. Any attempt to create a record and insert it in an abstract table will result in a run-time error

Insert Recrod on derived Table

static void dataInsert_tshirt(Args _args)
{

Tabtshirtsize tsize;
  
    tsize.Id=3;
    tsize.Brand="Lee";
    tsize.Name="T-Shirts";
    tsize.Size="S";
    tsize.insert();
    print "insert Record";
    pause;
   

}