美文网首页
Import vendor and address and co

Import vendor and address and co

作者: axxxxxxxx | 来源:发表于2017-10-26 12:36 被阅读0次

    This code introduces how to use a helper class to create vendor master, address book and contact information with the related vendor.

    private void CreateVendor ()
    {
    
        ACT_VendorMasterStaging         vendorMaster;
        VendTable                       curVendTable;
        DirPartyTable                   curDirPartyTable;
        LogisticsLocation               curLogisticsLocation;
        LogisticsPostalAddress          curLogisticsPostalAddress;
    
        Query                           q;
        Queryrun                        qr;
        QueryBuildDataSource            qbds;
        QueryBuildRange                 qbr;
    
        DirParty                        dirParty;
        DirPartyPostalAddressView       dirPartyPostalAddressView;
        DirPartyContactInfoView         dirPartyContactInfo;
        DirOrganization                 dirOrganization;
    
        ;
    
        q = new query();
        qbds  = q.addDataSource(tableNum(ACT_VendorMasterStaging));
        qbr   = qbds.addRange(fieldNum(ACT_VendorMasterStaging, import_status));
        qbr.value(enum2str(ACT_StagingImportStatus::Pending));
        qr = new QueryRun(q);
    
        while(qr.next())
        {
        try
        {
            ttsBegin;
            vendorMaster = qr.get(tableNum(ACT_VendorMasterStaging));
    
            dirOrganization.clear();
            dirOrganization.initValue();
            dirOrganization.Name = vendorMaster.VENDOR_NAME;
            dirOrganization.insert();
    
            if (dirOrganization)
            {
                curVendTable.clear();
                curVendTable.initValue();
                curVendTable.AccountNum = vendorMaster.VENDOR_CODE;
                curVendTable.VendGroup = "External";
                curvendTable.Party = dirOrganization.RecId;
                if (curvendTable.validateWrite())
                {
                    curvendTable.insert();
                }
    
            /* Creates a new instance of the DirParty class from an address book entity
                that is represented by the prospect parameter. */
    
                dirParty = DirParty::constructFromCommon(curVendTable);
                dirParty.parmName(vendorMaster.VENDOR_NAME);
                dirParty.parmNameAlias(vendorMaster.VENDOR_NAME);
                dirPartyPostalAddressView.clear();
                dirPartyPostalAddressView.LocationName      = vendorMaster.VENDOR_NAME;
                dirPartyPostalAddressView.City              = vendorMaster.ADDRESS4;
                dirPartyPostalAddressView.Street            = vendorMaster.ADDRESS1 + "---" + vendorMaster.ADDRESS2 + "---" + vendorMaster.ADDRESS3;
                dirPartyPostalAddressView.CountryRegionId   = vendorMaster.Import_Remarks;
                dirPartyPostalAddressView.ZipCode           = vendorMaster.POSTAL_CODE;
                dirPartyPostalAddressView.IsPrimary         = NoYes::Yes;
    
                dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
    
                // Fill Contacts
                dirPartyContactInfo.clear();
                if(vendorMaster.TEL1)
                {
                    dirPartyContactInfo.LocationName    = "TEL1";
                    dirPartyContactInfo.Locator         = vendorMaster.TEL1_COUNTRY +"-" + vendorMaster.TEL1_AREA + "-" + vendorMaster.TEL1;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
                    dirPartyContactInfo.IsPrimary       = NoYes::Yes;
    
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
                // Fill Contacts
                if(vendorMaster.TEL2)
                {
                    dirPartyContactInfo.LocationName    = "TEL2";
                    dirPartyContactInfo.Locator         = vendorMaster.TEL2_COUNTRY +"-" + vendorMaster.TEL2_AREA + "-" + vendorMaster.TEL2;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
                    dirPartyContactInfo.IsPrimary       = NoYes::No;
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
                // Fill Contacts
                if(vendorMaster.FAX1)
                {
                    dirPartyContactInfo.LocationName    = "FAX1";
                    dirPartyContactInfo.Locator         = vendorMaster.FAX1_COUNTRY +"-" + vendorMaster.FAX1_AREA + "-" + vendorMaster.FAX1;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Fax;
                    dirPartyContactInfo.IsPrimary       = NoYes::No;
                    // Fill Contacts
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
                if(vendorMaster.FAX2)
                {
                    dirPartyContactInfo.LocationName    = "FAX2";
                    dirPartyContactInfo.Locator         = vendorMaster.FAX2_COUNTRY +"-" + vendorMaster.FAX2_AREA + "-" + vendorMaster.FAX2;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Fax;
                    dirPartyContactInfo.IsPrimary       = NoYes::No;
    
                    // Fill Contacts
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
                if(vendorMaster.Email1)
                {
                    dirPartyContactInfo.LocationName    = "Email1";
                    dirPartyContactInfo.Locator         = vendorMaster.Email1;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
                    dirPartyContactInfo.IsPrimary       = NoYes::No;
    
                    // Fill Contacts
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
                if(vendorMaster.Email2)
                {
                    dirPartyContactInfo.LocationName    = "Email2";
                    dirPartyContactInfo.Locator         = vendorMaster.Email2;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
                    dirPartyContactInfo.IsPrimary       = NoYes::No;
    
                    // Fill Contacts
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
                if(vendorMaster.CONTACT)
                {
                    dirPartyContactInfo.LocationName    = "Contact Person";
                    dirPartyContactInfo.Locator         = vendorMaster.CONTACT_TITLE + "//" + vendorMaster.CONTACT;
                    dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Telex;
                    dirPartyContactInfo.IsPrimary       = NoYes::No;
    
                    // Fill Contacts
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
                }
    
    
                vendorMaster.Import_Status = ACT_StagingImportStatus::Pending;
                vendorMaster.selectForUpdate(true);
                vendorMaster.update();
            }
            // Marks the end of transaction.
            ttsCommit;
    
        }
        catch(Exception::Error)
        {
           ttsBegin;
           vendorMaster.Import_Status = ACT_StagingImportStatus::Error;
           vendorMaster.selectForUpdate(true);
           vendorMaster.update();
           ttsCommit;
    
           ttsAbort;
        }
    
        }
    
        info("Done");
     }
    

    相关文章

      网友评论

          本文标题:Import vendor and address and co

          本文链接:https://www.haomeiwen.com/subject/nxzhpxtx.html