Creating Vendors through X++ in AX 2012- PART IV

Creating Vendors through X++ in AX 2012- PART IV

--Create contact for the vendor--

private void createContact(VendorRequestCreate       _vendorRequestCreate,
                           RefRecId                     _partyId) 
{
    ContactPerson           contactPerson;
    DirPersonName           lDirPersonName;
    DirPerson               lDirPerson;
    DirParty                lDirParty;
    LogisticsLocation       lLogisticsLocation;
    DirPartyContactInfoView             lDirPartyContactInfoView; 
    ;
//Create party for Contact
    lDirPerson.Name                          = _vendorRequestCreate.ContactPersonName;
    lDirPerson.NameAlias                     = _vendorRequestCreate.ContactPersonName;
    lDirPerson.NameSequence                  = dirNameSequence::find('First Last').RecId;
    lDirPerson.insert();
    lDirPersonName.FirstName                 = _vendorRequestCreate.ContactPersonName;
//lDirPersonName.MiddleName                = _vendorRequestCreate.ContactPersonName;
//lDirPersonName.LastName                  = _vendorRequestCreate.LastName;
    lDirPersonName.ValidFrom                 = DateTimeUtil::newDateTime(systemDateGet(),str2time ('00:00:00'),DateTimeUtil::getUserPreferredTimeZone());
    lDirPersonName.ValidTo                   = DateTimeUtil::maxValue();
    lDirPersonName.Person                    = lDirPerson.RecId;
    lDirPersonName.insert();
    lDirParty                                = new DirParty(lDirPerson);
//Create contact and associate with party
    contactPerson.ContactForParty           = vendTable.Party;
    contactPerson.Party                     = lDirPerson.RecId;
    contactPerson.insert();
//Create contact number
if(_vendorRequestCreate.ContactPersonNo != '')
    {
        lLogisticsLocation.clear();
        lLogisticsLocation                  = LogisticsLocation::create('Phone', NoYes::No);
        lDirPartyContactInfoView.LocationName                = 'Primay Phone';
        lDirPartyContactInfoView.Locator                     = _vendorRequestCreate.ContactPersonNo;
        lDirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Phone;
        lDirPartyContactInfoView.Party                       = contactPerson.Party;
        lDirPartyContactInfoView.IsPrimary                   = NoYes::Yes;
        lDirParty.createOrUpdateContactInfo(lDirPartyContactInfoView);
    }
}
-Harry

Comments

Popular posts from this blog

Connecting to Databases through X++ PART -I

X++ code for document attachment

Multiple Tables In Query