Sunday, July 3, 2016

To Set Field Property in AX 2012

//To Set Field Property in AX 2012
#Property
fieldNode = TreeNode::findNode(@"\Data Dictionary\Tables\SalesQuotationTable\Fields\BankGuarantee");   
fieldNode.AOTsetProperty(#PropertyMandatory, enum2str(NoYes::Yes));

sample CSV files Upload

static void samplecsv(Args _args)
{
    CommaTextIO                 csvFile;
    container                   readCon;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField                 dfFileName;
    FileName                    fileName;
    ItemId      itemId;
     #File
//Sangeeth added
    dialog = new Dialog("Pick the file");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);

    if (dialog.run())
    {
        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();
        ttsBegin;
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();
            if(readCon)
            {
                icount++;
                itemId          =  conPeek(readCon,1);
                info(itemId);
            }
        }
        ttsCommit;
    }
}

To Add Budget Control for MainAccountType(

//To Add Budget Control for MainAccountType(Balance Sheet) Other than (Expenses,P&L,Totals) MainAccount in ax 2012
Path-->
AOT\Data Dictionary\Tables\BudgetControlMainAccount\Methods\budgetControlMainAccountTypes

public static Set budgetControlMainAccountTypes()
{
    Set mainAccountTypes;
    mainAccountTypes = new Set(Types::Enum);
    mainAccountTypes.add(DimensionLedgerAccountType::Expense);
    mainAccountTypes.add(DimensionLedgerAccountType::ProfitAndLoss);
    mainAccountTypes.add(DimensionLedgerAccountType::Total);
    //Add your MainAccount Type  Code Here - For Calculation of Budget Amount in Automatic Posting rule
    return mainAccountTypes;
}

Code C# --> Web form to AX data entry




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ServiceReference1.IntegrationCustomServiceClient clien = new ServiceReference1.IntegrationCustomServiceClient();
            clien.ClientCredentials.Windows.ClientCredential.UserName = "AosServiceUser";
            clien.ClientCredentials.Windows.ClientCredential.Password = "r1@jNjWtTMNcKx";
            clien.ClientCredentials.Windows.ClientCredential.Domain = "epgax.com";
            ServiceReference1.CallContext context = new ServiceReference1.CallContext();
            //ServiceReference1.ClsRegistration parm = new ServiceReference1.ClsRegistration();
            ServiceReference1.ClsPayment parm = new ServiceReference1.ClsPayment();
            ServiceReference1.ClsAXTransactionMessage[] getTransMsg = null;  // new ServiceReference1.ClsAXTransactionMessage[1];
            parm.AcademicYear = ServiceReference1.AcademicYear.Next;
            parm.TrasactionDate = DateTime.Today;
            parm.PaymentType = ServiceReference1.PayType.Fee;
            parm.Amount = 100;
            parm.CustomerAccount = "2001F";
            parm.AxDocDocumentNo = "2001F";
            parm.EFormDocumentNo = "EFORM2001F";
            parm.DimensionBU = "99";
            parm.DimensionCC = "37";
            parm.DimensionDept = "1";
            parm.Description = "Payment towards Next year student";
            context.Company = "EPGE";
            context.LogonAsUser = "AosServiceUser@epgax.com";
            context.Language = "EN-US";
            getTransMsg = clien.CreatePayment(context, parm);
            if (getTransMsg != null)
            {
                foreach (ServiceReference1.ClsAXTransactionMessage item in getTransMsg)
                {
                     MessageBox.Show(item.AxDocDocumentNo);
                     MessageBox.Show(item.EFormDocumentNo);
                     MessageBox.Show(item.AXOperationType);
                     MessageBox.Show(item.StatusMessage);
                     MessageBox.Show(item.SuccesFlag.ToString());
                }
              
            }
            clien.Close();
        }
    }
}

To Run .exe file in AX 2012

// To Run .exe file in AX 2012
WinAPI::ShellExecute();
CLass --> SysShellExecute
Method --> SysShellExecute--> Main
parameter --> Args

or else
class -->  System.Diagnostic.Process

To Delete Dimension Related Record

//To Delete Dimension Related Record

Error :: A financial dimension value is based on the "ID" record and
 has been used on a  transaction. You cannot delete the "ID" record

Delete Record from below Table. And then try to Delete

DimensionAttributeLevelValue
DimensionAttributeValueCombination
   DimensionAttributeLevelValue    attributeLevelValue;
    DimensionAttributeValueCombination  attributeValueCombination;

    ttsBegin;
    delete_from attributeValueCombination
        where attributeValueCombination.DisplayValue like ProjTable.ProjId;
    delete_from attributeLevelValue
        where attributeLevelValue.DisplayValue like ProjTable.ProjId;
    ttsCommit;
    super();

Set Field name label in ax 2012

static void SetLabels(Args _args)
{
    #Properties
    SysDictTable    dictTable = new SysDictTable(tableNum(CustTable));
    SysDictField    dictField;
    TreeNode        treeNode;
    FieldId         fieldId = dictTable.fieldNext(0);
    str             fieldName;
   
    while (fieldId)
    {
        dictField = dictTable.fieldObject(fieldId);
        if (dictField.isSql() && !dictField.isSystem())
        {
            treeNode = dictField.treeNode();
           
            fieldName = treeNode.AOTgetProperty(#PropertyName);
            treeNode.AOTsetProperty(#PropertyLabel, fieldName);
            treeNode.AOTsave();
           
            info(strFmt("Field name: %1 | Field label: %2",
                treeNode.AOTgetProperty(#PropertyName),         //Field name
                treeNode.AOTgetProperty(#PropertyLabel)));      //Field label
           
            treeNode.treeNodeRelease();
            treeNode = null;
        }
        fieldId = dictTable.fieldNext(fieldId);
    }
}

management Reporter Details Ax

management Reporter ax
http://www.ignify.com/management_reporter_for_dynamics_erp.asp
https://technet.microsoft.com/en-us/library/dn507082.aspx
https://msdn.microsoft.com/en-us/library/dn435963.aspx

Count Infolog lines ax 2012

info(strFmt("%1",infologLine()));
infolog.clear(infologLine());

Dynamics Integration using AIF

dynamics Integration using AIF

http://ax2012aifintegration.blogspot.com/2013_10_01_archive.html

Skip Inventory reservation on Sales order lines in D365FO

[ExtensionOf(classStr(InventUpd_Reservation))] final class InventUpd_ReservationCls_SAN_Extension {     void updateNow()     {         if(mo...