Thursday, April 4, 2024

Code to create Vendor using Entites in D365f&o x++

public static void main(Args _args)

   {

       VendAccount                         returnAccount;

       VendVendorBankAccountEntity         vendVendorBankAccountEntity;

       DirParty                            dirParty;

       DirPartyPostalAddressView           dirPartyPostalAddressView;

       LogisticsLocationRole               logisticsLocationRole;

       LogisticsLocationRoleTranslation    locationRoleTransl;

       VendTable                           vendTable;

       VendVendorV2Entity                  vendEntity;

       LogisticsAddressCountryRegionEntity logisticsAddressCountryRegionEntity;

       LogisticsAddressStateEntity         logisticsAddressStateEntity;

       LOGISTICSADDRESSPOSTALCODEV2ENTITY  logisticsAddressPostalCodeV2Entity;

       LOGISTICSADDRESSCITYENTITY          logisticsAddressCityEntity;

       LogisticsPostalAddressBaseEntity    logisticsPostalAddressBaseEntity;

       LogisticsLocation                   logisticsLocation;

       TaxInformation_IN                   taxInformation_IN;

       TaxRegistrationNumbers_IN            taxRegistrationNumber_IN;

       TaxGSTRegistrationNumberEntity   taxGSTRegistrationNumberEntity;

 

       changecompany("INMF")

       {

           vendEntity.initValue();

           

           select vendEntity

           where vendEntity.VendorAccountNumber == "000001";

 

           select locationRoleTransl

           join logisticsLocationRole

           where logisticsLocationRole.RecId == locationRoleTransl.LocationRole

           && locationRoleTransl.Description == "Delivery";

 

           vendEntity.VendorAccountNumber = "000001";

           vendEntity.VendorOrganizationName = "Fabrikam Brasil Ltda";

           vendEntity.VendorPartyType = "Organization";

           vendEntity.VendorSearchName = "Priyanka";

           vendEntity.VendorGroupId ="40";

           vendEntity.AddressLocationRoles = "Delivery";

           vendEntity.AddressDescription = "dax";

           vendEntity.AddressCountryRegionId = "ADF";

       

           select logisticsAddressCountryRegionEntity

               where logisticsAddressCountryRegionEntity.CountryRegion ==  "ADF";

           if(!logisticsAddressCountryRegionEntity)

           {

               logisticsAddressCountryRegionEntity.AddressFormat = "0001";

               logisticsAddressCountryRegionEntity.CountryRegion =   "ADF";

               logisticsAddressCountryRegionEntity.insert();

           }

           vendEntity.AddressStateId = "TS";

           select  logisticsAddressStateEntity

           where logisticsAddressStateEntity.State ==  "TS"

           && logisticsAddressStateEntity.CountryRegionId ==   "ADF";

           if(!logisticsAddressStateEntity)

           {

               logisticsAddressStateEntity.CountryRegionID =  "ADF";

               logisticsAddressStateEntity.State = "TS";

               logisticsAddressStateEntity.insert();

           }

           vendEntity.AddressCity = "MGLL";

           select * from logisticsAddressCityEntity

               where logisticsAddressCityEntity.Name ==  "MGLL"

               && logisticsAddressCityEntity.CountryRegionId ==   "ADF"

               && logisticsAddressCityEntity.StateId == "TS";

           if(!logisticsAddressCityEntity)

           {

               logisticsAddressCityEntity.CountryRegionId ="ADF";

               logisticsAddressCityEntity.StateId =  "TS";

               logisticsAddressCityEntity.Name = "MGLL";

               logisticsAddressCityEntity.CityKey =  "MGLL, TS, ADF";

               logisticsAddressCityEntity.insert();

           }

           vendEntity.AddressZipCode = "506006";

 

           select logisticsAddressPostalCodeV2Entity

           where logisticsAddressPostalCodeV2Entity.ZipCode ==  vendEntity.AddressZipCode;

           if(!logisticsAddressPostalCodeV2Entity)

           {

               logisticsAddressPostalCodeV2Entity.CountryRegionId =  logisticsAddressCountryRegionEntity.CountryRegion;

               logisticsAddressPostalCodeV2Entity.ZipCode = vendEntity.AddressZipCode;

               logisticsAddressPostalCodeV2Entity.insert();

           }

   

           vendEntity.PrimaryPhoneNumber = "1234567689";

           vendEntity.PrimaryPhoneNumberDescription = "test";

           vendEntity.PrimaryPhoneNumberPurpose = "Business";

           vendEntity.PrimaryEmailAddress = "test@gmail.com";

           vendEntity.PrimaryEmailAddressDescription = "test mail";

           vendEntity.PANNumber = "BAAAA1234a";

           

           if(vendEntity)

           {

               vendEntity.selectForUpdate(true);

               ttsbegin;

               vendEntity.update();

               ttscommit;

           }

           else

           {

               vendEntity.insert();

           }

           select vendVendorBankAccountEntity

               where vendVendorBankAccountEntity.VendorBankAccountId =="012";

          

           vendVendorBankAccountEntity.initValue();

           vendVendorBankAccountEntity.VendorBankAccountId = "012";

           vendVendorBankAccountEntity.BankName = "HDFC";

           vendVendorBankAccountEntity.BankAccountNumber = "9876543210";

           vendVendorBankAccountEntity.VendorAccountNumber = vendEntity.VendorAccountNumber;

 

           if(vendVendorBankAccountEntity)

           {

               vendVendorBankAccountEntity.selectForUpdate(true);

               vendVendorBankAccountEntity.update();

           }

           else

           {

               vendVendorBankAccountEntity.insert();

           }

           dirParty = DirParty::constructFromCommon(vendEntity);

           dirPartyPostalAddressView.City = 'MGLL';

           dirPartyPostalAddressView.Street = 'Dover Street';

           dirPartyPostalAddressView.StreetNumber = '123';

           dirPartyPostalAddressView.CountryRegionId = 'ADF';

           dirPartyPostalAddressView.LocationName = "JNTUHW";   

           container   _roles = [logisticsLocationRole.RecId,locationRoleTransl.Description,locationRoleTransl.RecId];

           dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,_roles);

         

           select  taxGSTRegistrationNumberEntity

               where taxGSTRegistrationNumberEntity.RegistrationNumber == '29AGNPB4831B1Z4';

           if(!taxGSTRegistrationNumberEntity)

           {

               taxGSTRegistrationNumberEntity.RegistrationNumber = '29AGNPB4831B1Z4';

               taxGSTRegistrationNumberEntity.Description = 'CodeTax';

               taxGSTRegistrationNumberEntity.RegistrationNumberType = TaxRegistrationType_IN::Vendors;

               taxGSTRegistrationNumberEntity.insert();

           }

           select logisticsLocation

                order by logisticsLocation.recid desc

               where logisticsLocation.Description == "JNTUHW";

              

           select taxInformation_IN

               where taxInformation_IN.RegistrationLocation == logisticsLocation.RecId;

           if(!taxInformation_IN)

           {

               taxInformation_IN.RegistrationLocation = logisticsLocation.RecId;

               taxInformation_IN.GSTIN = taxGSTRegistrationNumberEntity.RecId;

               taxInformation_IN.Name =taxGSTRegistrationNumberEntity.Description;

               taxInformation_IN.insert();

           }

           returnAccount = vendEntity.VendorAccountNumber;

           Info(strFmt("%1",returnAccount));

       }

   }

.....................

OutPut:








No comments:

Post a Comment