Tuesday 8 April 2014

Job to import customer contact information- Logistics electronic address

static void CustomerContactInformationJob(Args _args)
{
#File
    CommaTextIo        commaTextIo;
    FileIOPermission   permission;
    container          containFromRead;
    int                x;
    int                cols;
    int rowNum;

    str Customer,Description,Type,Locator;
    int Done,UnDone;

    CustTable custTAble;
    DirPartyContactInfoView DirPartyContactInfoView;
    DirParty dirParty;
    List locatorList;
    ListEnumerator locatorListEnumerator;
    SysDictEnum dictEnum;
    int         enumValue;

    ;
    permission = new FileIOPermission(@'C:\Users\Administrator\Desktop\Data\CustomerContacts.csv',#io_read);
    permission.assert();

    commaTextIo = new CommaTextIO(@'C:\Users\Administrator\Desktop\Data\CustomerContacts.csv','R');

    rowNum = 0;
    Done= 0;
    UnDone= 0;

    containFromRead = commaTextIo.read();

    dictEnum = new SysDictEnum(enumNum(LogisticsElectronicAddressMethodType));

    While(containFromRead)
    {
        if(rowNum>0)
        {
            Customer= any2str(conpeek(containFromRead,1));
            Description= any2str(conpeek(containFromRead,2));
            Type= any2str(conpeek(containFromRead,3));
            Locator= any2str(conpeek(containFromRead,4));

            custTable =CustTable::find(Customer);

    if(custTable)
        {
            dirParty = dirParty::constructFromPartyRecId(custTAble.Party);

            locatorList = strSplit(Locator, ";");
            locatorListEnumerator = locatorList.getEnumerator();

            while ( locatorListEnumerator.moveNext())
            {

                DirPartyContactInfoView.Locator = locatorListEnumerator.current();
                DirPartyContactInfoView.Type =   dictEnum.name2Value(Type);

                DirPartyContactInfoView.Party =   custTable.Party;
                DirPartyContactInfoView.LocationName = Description;
                dirParty.createOrUpdateContactInfo(DirPartyContactInfoView);

                DirPartyContactInfoView.clear();
                Done++;

            }



        }
        else
        {
            info("Customer not found " + Customer);
            UnDone++;
        }


        }
        containFromRead = commaTextIo.read();
        rowNum++;
    }
    commaTextIo = null;

    info(strFmt("Inserted : %1 Not inserted: %2", Done, UnDone));
}

tags: Ax 2012 Customer contact information ; Logistics Electronic address; importing contacts from csv using x++;

2 comments: