Create Contact Person for Vendor Or Customer AX 2012 & D365FO



Create Contact Person for Vendor Or Customer AX 2012 & D365FO



Important

In D365FO use ContactPersonSyncEntity class and in AX 2012 use ContactPersonEntity 



Using below code you can create contact person against Customer or Vendor in AX 2012 & D365FO.





class SLD_DemoInstance
{





    
    public static void main(Args _args)
    {

        // Declare variables: views.
        DirPartyContactInfoView contactInfo;
        DirPartyPostalAddressView postalAddress;

        // Declare variables: tables.
        ContactPerson contactperson;

        DirPartyTable partyTable = DirPartyTable::findRec(VendTable::find("S00038").Party);
   
        // Declare variables: classes.
        ContactPersonEntity contactPersonEntity;

   

  
        // Create and populate the contact person.

        contactPersonEntity = ContactPersonEntity::construct(contactPerson);
      
        contactPersonEntity.parmFirstName("FirstName");
        contactPersonEntity.parmMiddleName('M.');
        contactPersonEntity.parmLastName('Person');
        contactPersonEntity.parmAssistantName('AssistantName');
        contactPersonEntity.parmBillingInformation('Billing info');
        contactPersonEntity.parmCharacter('Character description');
        contactPersonEntity.parmComputerNetworkName('Computer network name');
        contactPersonEntity.parmContactForParty(partyTable.RecId);
        contactPersonEntity.parmContactMemo('Memo');
        contactPersonEntity.parmContactPersonId('CP64');
        contactPersonEntity.parmLoyalty('Loyalty');
        contactPersonEntity.parmMileage('Mileage');
        contactPersonEntity.parmOfficeLocation('Office location');
        contactPersonEntity.parmOutlookCategories('Outlook categories');
        contactPersonEntity.parmProfession('Profession');
        contactPersonEntity.parmSensitivity(smmSensitivity::Personal);
        contactPersonEntity.parmSpouse('Spouse');
        contactPersonEntity.parmTimeAvailableFrom(1000);
        contactPersonEntity.parmTimeAvailableTo(2000);
        contactPersonEntity.write();

        // Populate the postal address information by using the view.
        postalAddress.clear();
        postalAddress.Street = 'One Microsoft Way';
        postalAddress.City = 'Redmond';
        postalAddress.State = 'WA';
        postalAddress.ZipCode = '98052';
      
        postalAddress.Address="QAR";
        postalAddress.CountryRegionId = "Country Region ID";


        // Update the postal address information.
        contactPersonEntity.createOrUpdatePostalAddress(postalAddress);


        //phone

        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="Phone";
        contactInfo.Locator = "123456";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Phone;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);




      
        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="Email";
        contactInfo.Locator ="abcd@gmail.com";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Email;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);



        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="FAX";
        contactInfo.Locator ="98798789798";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Fax;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);

    }

}

How to get Vendors or Customer Contact Information Primary & None Primary




 How to get Vendors or Customer  Contact Information Primary & None Primary



Via below code you can get the Vendor/Customer complete contact information (Primary & None Primary).

  LogisticsElectronicAddress logisticsElectronicAddress;
        DirPartyLocation        dirLocation;
        DirPartyTable dirPartyTable=DirPartyTable::findRec(VendTable::find("S00038").Party);
     
        while select  logisticsElectronicAddress
        join dirLocation  where dirLocation.Location==logisticsElectronicAddress.Location
            && dirLocation.Party==dirPartyTable.RecId
        {
            info(strFmt("%1",logisticsElectronicAddress.Locator));
        }

How to get Vendor's or Customer's Contact Person's Contact Information




How to get  Vendor's or Customer's  Contact Person's Contact Information

Via below code you can get the Vendor/Customer contact person and their complete contact information.


class SLD_DemoInstance
{





   
    public static void main(Args _args)
    {

        ContactPerson            contactPerson;
        DirPartyTable       dirPartyTable;
        LogisticsElectronicAddress      address;
   
        DirPartyLocation        partylocation;
   
   
        RecId _refRecId= VendTable::find("S00038").Party;
        while select contactPerson
         where contactPerson.ContactForParty==_refRecId
        join dirPartyTable
        where dirPartyTable.RecId==contactPerson.Party
        join partylocation
        where partylocation.Party==contactPerson.Party
        outer join address
        where address.Location==partylocation.Location
      
        {
       
            info(strFmt("%1, %2, %3",contactPerson.ContactPersonId,contactPerson.personName(),address.Locator));
        }
    }


}




How to get Contact Person of Vendor & Customer



How to get Contact Person of Vendor & Customer 


Via below code you can retrieve the contact person list of vendor or customer


class SLD_DemoInstance
{

   
    public static void main(Args _args)
    {

        ContactPerson            contactPerson;
        DirPartyTable       dirPartyTable;
   
        RecId _refRecId= VendTable::find("S00038").Party;
        while select contactPerson
        where contactPerson.ContactForParty==_refRecId
        {
       
            info(strFmt("%1, %2",contactPerson.ContactPersonId,contactPerson.personName()));
        }
    }

}

How to get Vendors or Customer Primary Contact Information




How to get Vendors or Customer Primary Contact Information

Via below code you can get the Vendor/Customer complete contact information.

Important 
In AX 2012 PrimaryContactLinkedInPrimaryContactFacebook fields are not available.

class SLD_DemoInstance
{
   
    public static void main(Args _args)
    {

        LogisticsElectronicAddress logisticsElectronicAddress;
        DirPartyTable dirPartyTable=DirPartyTable::findRec(VendTable::find("K-DR-000001").Party);
     
        while select  logisticsElectronicAddress where (logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactEmail ||
            logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactPhone || logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactFacebook ||
            logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactFax || logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactLinkedIn)

        {
            info(strFmt("%1",logisticsElectronicAddress.Description));
        }
    }


}




VSTS Add External User



How to Invite External user on your VSTS


One of my colleague was want to add external user in VSTS. but while he is trying to add external user and typing user name then only organization users are appearing in the drop down.



Resolution

Login to Azure Active Portal with admin right or contact you AD administrator

Go to Azure Active Directory 


Select Users Menu

Now click on New Guest User and save it.



Now login again to your VSTS and try to add users


Item Attribute



Item Attribute
Query relation to getting Item attributes.




InventTable                                             objinventTable;
EcoResProduct                                        objecoResProduct;
EcoResValue                                           objecoResValue;
EcoResAttributeValue                             objecoResAttributeValue;
EcoResAttribute                                      objecoResAttribute;
EcoResInstanceValue                              objecoResInstanceValue;
EcoResAttributeType                              objecoResAttributeType;
EcoResProductInstanceValue                 objecoResProductInstanceValue;
int i = 0;
;
while select objecoResAttributeValue
join objecoResAttribute
where objecoResAttributeValue.Attribute == objecoResAttribute.RecId
join objecoResAttributeType
where objecoResAttribute.AttributeType == objecoResAttributeType.RecId
join objecoResInstanceValue
where objecoResAttributeValue.InstanceValue == objecoResInstanceValue.RecId
join objecoResValue
where ecoResAttributevalue.Value == objecoResValue.RecId
join objecoResProductInstanceValue
where objecoResInstanceValue.RecId == objecoResProductInstanceValue.RecId
join objecoResProduct
where objecoResProduct.RecId == objecoResProductInstanceValue.Product
join objinventTable
where objinventTable.Product == objecoResProduct.RecId
&& objinventTable.itemid='D0001'
{
     info(strFmt("%1 %2",objecoResProduct.DisplayProductNumber,objecoResAttribute.Name));
}

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...