Thursday, January 21, 2016

// Upload Vendor Address in ax 2012
static void Fcc_UploadVendorAddress(Args _args)
{
    CommaTextIO                             csvFile;
    int                     row = 1;
    int                     i = 0;
     container                               readCon;
     counter                                 icount,inserted;
     Dialog                                  dialog;
     DialogField                             dfFileName;
     DirPartyRecId                           partyRecId,contactPartyRecid;
     VendTable                               vendtable;
     str                                     contactperson;
     DirPartyPostalAddressView               addressView;
     DirPartyContactInfoView                 contactView;
     ContactPerson                           contactpersonTable;
     LogisticsElectronicAddressMethodType    enumType;
     DirContactPersonsService                dirContactPersonsService;
     DirContactPersons                       dirContactPersons;
     DirContactPersons_ContactPerson         dirContactPersons_ContactPerson;
     DirContactPersons_Person                dirContactPersons_Person;
     DirContactPersons_PersonName            dirContactPersons_PersonName;
     AifEntityKeyList                        aifEntityKeyList, aifEntityKeyList_DirContactPerson;
     str                                     fName, mName, lName;
     VendAccount                             vendorAccount;
     DirParty                                dirParty;
     LogisticsPostalAddress                  address;
     LogisticsElectronicAddress              logisticsElectronicAddress;
     BinData                                 binData;
     str                                     stringImage;
     LogisticsAddressStateID                 stateId;
     str                                     accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
     Filename filename;
    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    COMVariantType          type;
    ;
    #File
    dialog     = new Dialog("Select Excel to Import");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    if (dialog.run())
    {
        filename    = dfFileName.value();
        application = SysExcelApplication::construct();
        workbooks   = application.workbooks();
        try
        {
            workbooks.open(filename);
        }
        catch (Exception::Error)
        {
            throw error("File cannot be opened.");
        }
        workbook    = workbooks.item(1);
        worksheets  = workbook.worksheets();
        worksheet   = worksheets.itemFromNum(1);
        cells = worksheet.cells();
        do
        {
                row++;
                accountnum = cells.item(row,1).value().bStr();
                street = cells.item(row,5).value().bStr();
                countryid = cells.item(row,2).value().bStr();
                //fax =cells.item(row,5).value().bStr();
                phone = cells.item(row,3).value().bStr();
                //mobile = cells.item(row,7).value().bStr();
            Email = cells.item(row,4).value().bStr();
                 vendtable = vendtable::find(accountnum);
                address.clear();
                 address.CountryRegionId = strLRTrim(Countryid);
                 address.Street  = strLRTrim(Street);
                addressView.clear();
                 addressView.IsPrimary = NoYes::Yes;
                 addressView.Party = vendtable.Party;
                 addressview.initFromPostalAddress(address);
                 DirParty = DirParty::constructFromPartyRecId(addressView.Party );
                 DirParty.createOrUpdatePostalAddress(addressView);

                    /*if(mobile)
                    {
                        contactView.clear();
                         contactView.LocationName = "Mobile";
                         contactView.Locator      = strLRTrim(mobile);
                         contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                         contactView.Party        = vendtable.Party;
                         contactView.IsPrimary    = NoYes::Yes;
                         dirParty.createOrUpdateContactInfo(contactView);
                    }*/
                    if(Phone)
                    {
                        contactView.clear();
                         contactView.LocationName = "Phone";
                         contactView.Locator      = strLRTrim(Phone);
                         contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
                         contactView.Party        = vendtable.Party;
                         contactView.IsPrimary    = NoYes::Yes;
                         dirParty.createOrUpdateContactInfo(contactView);
                    }
                    if(Email)
                    {
                        contactView.clear();
                         contactView.LocationName = "Email";
                         contactView.Locator      = strLRTrim(Email);
                         contactView.Type         = LogisticsElectronicAddressMethodType::Email;
                         contactView.Party        = vendtable.Party;
                         contactView.IsPrimary    = NoYes::Yes;
                         dirParty.createOrUpdateContactInfo(contactView);
                    }
                    /*if(fax)
                    {
                        contactView.clear();
                         contactView.LocationName = "Fax";
                         contactView.Locator      = strLRTrim(Fax);
                         contactView.Type         = LogisticsElectronicAddressMethodType::Fax;
                         contactView.Party        = vendtable.Party;
                         contactView.IsPrimary    = NoYes::Yes;
                         dirParty.createOrUpdateContactInfo(contactView);
                    }*/
                 i++;
                type        = cells.item(row+1, 1).value().variantType();
             }
        while (type != COMVariantType::VT_EMPTY);
        application.quit();
        info(strFmt(" No of Records updated is %1",i));
    }
}

//Vendor Contact person upload

vendTable = VendTable::find(account);
                    dirPerson.clear();
                    dirPerson.Name                          = personName;
                    dirPerson.NameAlias                     = personName;
                    dirPerson.NameSequence                  = dirNameSequence::find('First Last').RecId;
                    dirPerson.insert();
                    dirPersonName.clear();
                    dirPersonName.FirstName                 = personName;
                    dirPersonName.ValidFrom                 = DateTimeUtil::newDateTime(systemDateGet(),str2time ('00:00:00'),DateTimeUtil::getUserPreferredTimeZone());
                    dirPersonName.ValidTo                   = DateTimeUtil::maxValue();
                    dirPersonName.Person                    = dirPerson.RecId;
                    dirPersonName.insert();
                    dirParty                                = new DirParty(dirPerson);
                    ttsBegin;
                    contactPerson.ContactPersonId           = NumberSeq::newGetNum(CompanyInfo::numRefContactPersonId()).num();
                    contactPerson.ContactForParty           = vendTable.Party;
                    contactPerson.Party                     = dirPerson.RecId;
                    contactPerson.insert();
                    ttsCommit;
                   
                    if(Email)
                    {
                    dirPartyContactInfoView.LocationName                = 'Email';
                    dirPartyContactInfoView.Locator                     = Email;
                    dirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Email;
                    dirPartyContactInfoView.Party                       = contactPerson.Party;
                    dirPartyContactInfoView.IsPrimary                   = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfoView);
                    }





No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...