Pages

Friday, 16 October 2015

ClrObject static method invocation error

    When we deleting file by using WinAPIServer class we get following issue ClrObject static method invocation error.

Solution:

             Deleting file does not exist in the particular location. So the error occured..
                         i) We need to check file exist or not by using System.IO.File::Exists("FileName") method

Sample Code:

static void Delfile(Args _args)
{
    FilePath            filePath;
    FileIOPermission    fileIOPermission;
    ;

    filePath = @'C:\customer.xml';
    fileIOPermission = new FileIOPermission(filePath, 'w');
    CodeAccessPermission::revertAssert();
 

    //Here we adding File Exists method
    if(System.IO.File::Exists(filePath)) 
    {
        WinAPIServer::deleteFile(filePath);
    }
}
                     

Friday, 14 August 2015

CIL Error :Duplicate type with name ‘Dynamics.Ax.application.’ in assembly ‘Dynamics.Ax.application.tablename, version=6.0.9, culture… In Ax2012

Solving  this issue to perform the follow the instructions:
1) Full  Compile  Ax
2) Stop AOS Services.
3) Go to the Server Path: C:\Program Files\Microsoft Dynamics AX\60\Server\InstanceName\bin\XppIL \ delete all DLL and netModule files.
4) Truncate the records in the SysXppAssembly table in the Model database. 
     syntax: Truncate table SysXppAssembly .
5) Start the AOS.
6) Perform Full CIL Compilation.

Monday, 8 June 2015

Reading AIF outbound xml with multiple child nodes via jobs in dynamics ax 2009

static void XMLReadList(Args _args)
{
    XMLDocument     doc;
    XMLNode         rootNode,NodeAccount;
    XMLNodeList     xmlRootNodeList;
    XmlNodeList     xmlRecordList;
    XMLParseError   xmlError;
    XmlElement      xmlBodyField,xmlMessageField,xmlbbbField,xmlCustTableField;
    XmlNodeList     xmlBodyFieldList,xmlMessageBodyChildFieldList,xmlbbbaxdcustomerChildFieldList,xmlCustTableFieldList,xmlDirTableFieldList,xmlAddFieldList,xmlDirFieldList;
    XmlElement      xmlRecord,xmlMessageChildRecord,xmlbbbaxdcustomerChildRecord,xmlCustTableRecord,xmlDirTableRecord,xmlAddRecord;
    str             custAccount,cellularPhone,phone,email,street,state,city,zipcode,fname,lname,bbb_birthday,bbb_spousename,birthdate,anniversaryDate;
    int             i,j,k,l,m,n,p,fieldId;
    CustTable       custTable;

    ;
    // Read the XML Document
    doc = new XMLDocument();
    //doc.async(FALSE);
    doc.load(@"E:\\demo.xml");
    // Verify Document Structure
    xmlError  = doc.parseError();
    if(xmlError && xmlError.errorCode() != 0)
    {
        throw error(strFmt("Error: %1",xmlError.reason()));
    }
    // Parsing document contents
    rootNode = doc.documentElement();
    xmlRootNodeList = doc.documentElement().selectNodes("//Envelope");
    // Get all Customer information from XML document tags (and remove it)
    NodeAccount = doc.getNamedElement('Envelope');
    xmlRootNodeList = NodeAccount.childNodes();
    if(doc.getElementsByTagName('CustTable').length() > 0)
    {
        for(i=0;i<xmlRootNodeList.length();i++)
        {
            xmlRecord = xmlRootNodeList.item(i);
            if(i==1)
            {
                xmlBodyFieldList = xmlRecord.childNodes();

                for (j=0; j<xmlBodyFieldList.length(); j++)
                {
                    xmlBodyField = xmlBodyFieldList.item(j);
                    xmlMessageBodyChildFieldList = xmlBodyField.childNodes();

                    for(k=0;k<xmlMessageBodyChildFieldList.length();k++)
                    {
                        xmlMessageChildRecord = xmlMessageBodyChildFieldList.item(k);
                        xmlbbbaxdcustomerChildFieldList = xmlMessageChildRecord.childNodes();
                        if(xmlbbbaxdcustomerChildFieldList.length() > 0)
                        {
                            for(j=0;j<xmlbbbaxdcustomerChildFieldList.length();j++)
                            {
                                xmlbbbaxdcustomerChildRecord = xmlbbbaxdcustomerChildFieldList.item(j);
                                xmlCustTableFieldList = xmlbbbaxdcustomerChildRecord.childNodes();
                                custAccount      = xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('AccountNum').text();


                                if(xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('CellularPhone'))
                                {
                                    cellularPhone    = xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('CellularPhone').text();
                                }
                                if(xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('Email'))
                                {
                                    email            = xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('Email').text();
                                }
                                if(xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('Phone'))
                                {
                                    phone = xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('Phone').text();
                                }
                                xmlDirTableFieldList = xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('DirPartyTable').childNodes();
                                fname ='';
                                lname ='';
                                for(m=0;m<xmlDirTableFieldList.length();m++)
                                {
                                    if( xmlDirTableFieldList.item(m).baseName() == 'FirstName')
                                    {
                                        fname = xmlDirTableFieldList.item(m).text();
                                    }
                                    if( xmlDirTableFieldList.item(m).baseName() == 'LastName')
                                    {
                                        lname = xmlDirTableFieldList.item(m).text();
                                    }
                                    xmlDirFieldList = xmlDirTableFieldList.item(m).childNodes();

                                    birthday = '0000-00-00 00:00:00';
                                    spousename = '';
                                    birthdate = '0000-00-00 00:00:00';
                                    AnniversaryDate = '0000-00-00 00:00:00';
                                    for(p=0;p<xmlDirFieldList.length();p++)
                                    {

                                         if(xmlDirFieldList.item(p).baseName()=='Spouse_Birthday')
                                         {
                                            birthday = xmlDirFieldList.item(p).text();
                                         }

                                         if(xmlDirFieldList.item(p).baseName()=='Spouse_Name')
                                         {
                                            spousename = xmlDirFieldList.item(p).text();
                                         }

                                         if(xmlDirFieldList.item(p).baseName()=='BirthDate')
                                         {
                                            birthdate = xmlDirFieldList.item(p).text();
                                         }

                                         if(xmlDirFieldList.item(p).baseName()=='AnniversaryDate')
                                         {
                                            anniversaryDate = xmlDirFieldList.item(p).text();
                                         }
                                    }

                                }
                                xmlAddFieldList = xmlbbbaxdcustomerChildFieldList.item(j).getNamedElement('Address_1').childNodes();
                                city    ='';
                                state   ='';
                                street  ='';
                                zipcode ='';
                                for(n=0;n<xmlAddFieldList.length();n++)
                                {
                                    if(xmlAddFieldList.item(n).baseName() == 'City')
                                    {
                                        city = xmlAddFieldList.item(n).text();
                                    }
                                    if(xmlAddFieldList.item(n).baseName() == 'State')
                                    {
                                        state = xmlAddFieldList.item(n).text();
                                    }
                                    if(xmlAddFieldList.item(n).baseName() == 'Street')
                                    {
                                        street = xmlAddFieldList.item(n).text();
                                    }
                                    if(xmlAddFieldList.item(n).baseName() == 'ZipCode')
                                    {
                                        zipcode = xmlAddFieldList.item(n).text();
                                    }
                                }
                            }
                        }
                        else
                        {
                            info("Xml File is Empty");
                        }
                    }
                }
            }
        }
     }
     else
     {
        info("Xml File is Empty");
     }
}

Wednesday, 27 May 2015

Creating Customer Via Job In Dynamics Ax 2009

static void CustomerCreation(Args _args)
{
    CustTable                           CustTable;
    DirpartyTable                       DirpartyTable;
    DirPersonPartyDetail                DirPersonPartyDetail;
    DirPartyAddressRelationship         DirPartyAddressRelationship;
    Address                             Address;
    DirPartyAddressRelationshipMapping  DirPartyAddressRelationshipMapping;
    NumberSeq                           numberSeq;
    ;
    ttsbegin;
    CustTable.initValue();
    CustTable.AccountNum ="1000002";
    CustTable.CustGroup = "Test";
    CustTable.Name ="Ram Paul";
    CustTable.PartyId = NumberSeq::newGetNum(DirParameters::numRefDirPartyId()).num();
    CustTable.PartyType = DirPartyType::Person;
    CustTable.Phone = "9600341450";
    CustTable.Email = "RamPaul@rediffmail.com";
    CustTable.LanguageId = "en-us";
    if(CustTable.validateWrite())
    {
         CustTable.insert();
    }

    DirpartyTable.PartyId = CustTable.PartyId;
    DirpartyTable.FirstName = 'Ram';
    DirpartyTable.LastName  = 'Paul';
    DirpartyTable.insert();

    DirPersonPartyDetail.PartyId = DirpartyTable.PartyId;
    DirPersonPartyDetail.BBB_Spouse_Name = 'Nila';
    DirPersonPartyDetail.insert();

    dirparty::updatePartyFromCommonInsert(CustTable.PartyId, CustTable);

    select DirpartyTable where DirpartyTable.PartyId == CustTable.PartyId;

    Address.clear();
    Address.initValue();
    Address.AddrTableId = DirpartyTable.TableId;
    Address.AddrRecId = DirpartyTable.RecId;
 
    Address.Street = 'Knowledge Village';
    Address.City = 'Lawrenceburg';
    Address.CountryRegionId = 'US';
    Address.ZipCode = '47025';

    Address.CountryRegionId = 'US';
    Address.State = 'IN';
    Address.County = 'DEARBORN' ;
    Address.Address = Address::formatAddress(Address.City,Address.ZipCode,Address.Street,Address.CountryRegionId,Address.State,Address.County);
    Address.insert();
    ttscommit;

}

Wednesday, 24 September 2014

Creating A Record in CustTrans Form During An Invoice Process In Sales Order Form

                            Classes------>SalesFormLetter_Invoice------>createCustTrans() Method Will Start the Process.
                            Class--------------->CustVendVoucher------>post()  Method Will Do The Insert....

Another Easiest Way Is Go To Tables---->CustTrans----->insert() method you will Give which field you want to flown from CustTable To CustTrans Table.....

creating the Map:
                          create  new fields in both table CustTable,CustTrans Tables   and then go ------>AOT------>DataDictionary------>Map---->Select the CustTrans--->add fields in custTrans mapping fields....
select Mapping ---->Give Mapped Field property --> to Remarks fields.
Goto Class----->CustVoucher---->In initCustTransTable--->Add code 

custTrans.Remarks = custTable::Find(custTrans.AccountNum).Remarks;

thats it

For Example...
Creating a new field as Remarks in CustTable and also same way to create Remark field in CustTrans.I mean customer form - transactions button
when we post sales order invoice, I want customer table remarks to be flown to customer transactions form .....So just go to table custTrans open the insert method  and paste the following code....

this .Remarks = custTable::find(this.OrderAccount).Remarks;

Thats it......

Monday, 22 September 2014

Freezing Multiple Records In Dynamics Ax 2009

In Some time we want to freeze or read only for current active records.Here am showing hoe to freeze multiple records at one shot.

Example:

Write Following Code In form Design Button Click
---------------------------------------------
void clicked()
{
   ProductInform productInform1,productInform2;
    Container con,conrec;
    int i ;

    ;
    productInform2 = ProductInform_DS.getFirst();
    productInform1 = ProductInform_DS.getFirst();
    i = 1;

    for(productInform1 = ProductInform_DS.getFirst(true) ? ProductInform_DS.getFirst(true) : ProductInform_DS.cursor() ;
        productInform1; productInform1 = ProductInform_DS.getNext() )
        {
            con = conIns(con,i,productInform1.Status);
            conrec = conIns(conrec,i,productInform1.RecId);


            if(conPeek(con,i) != 0)
            {
                throw error("You are not selected Open Order");
            }
            i++;
        }
    ttsbegin;
    if(i == 2)
    {

        select forupdate productInform1 where productInform1.RecId == productInform2.RecId;

        if(productInform1)
        {
            productInform1.Status = statusIdea::Posted;
            productInform1.Permissions = permissions::No;
            productInform1.update();
        }
        ProductInform_DS.reread();
        ProductInform_DS.refresh();
        ProductInform_DS.active();

    }
    else
    {
        for(productInform2 = ProductInform_Ds.getFirst(1) ? ProductInform_DS.getFirst(1) : productInform2 ;productInform2; productInform2 = ProductInform_DS.getNext())
        {
            select forupdate productInform1 where productInform1.RecId == productInform2.recId;

            if(productInform)
            {
                productInform1.Status = StatusIdea::Posted;
                productInform1.Permissions = permissions::No;
                productInform1.update();
            }
        }

    ProductInform_DS.research(true);
    }
    ttscommit;

    super();
}

----------------------------------------------------------------
Write Following Code In Form DataSource Active Method
------------------------------------------------------------

public int active()
{
    int ret;
    ;
    ret = super();

    if(ProductInform.Permissions == permissions::No)
    {

        ProductInform_DS.allowEdit(false);
        Button.enabled(false);

    }
    else
    {
        ProductInform_DS.allowEdit(true);
        Button.enabled(true);
    }


    return ret;
}

Wednesday, 17 September 2014

X++ Code For Run a Form Using Class Factory

Class FormRunUsingClassFactory
{
    Args args;
    FormRun formRun;
}

Void CallingForm()
{
   args = New Args(FormStr(CustTable));////Here Mention the Name of the Form
   formRun = ClassFactory.FormRunClass(args);
   formRun.init();
   formRun.run();
   formRun.detach();
}

Public Static Void Main(Args args)
{
   FormRunUsingClassFactory formcf;
   ;
   formcf = New FormRunUsingClassFactory();
   formcf.CallingForm();
}