Wednesday, April 17, 2024

How to add custom element in SalesLedgerDimension of ItemGroups in D365F&O

My requirement is to add a custom element in item group of salesledgerdimension

InventoryManagement>Inventory>Item Groups

Add the Custom element in the following base enums :

1.InventAccountType

2.InventAccountTypeSales

3.LedgerPostingType.




Create a class and add these eventhandlers.

internal final class DaxInventGroupForm_EventHandler

{

   /// <summary>

   ///

   /// </summary>

   /// <param name="_inventAccountType"></param>

   /// <param name="_result"></param>

   [SubscribesTo(tableStr(InventItemGroupForm), delegateStr(InventItemGroupForm, ledgerDimensionDescriptionDelegate))]

   public static void InventItemGroupForm_ledgerDimensionDescriptionDelegate(InventAccountType _inventAccountType, EventHandlerResult _result)

   {

       switch(_inventAccountType)

       {

        case InventAccountType::Dax:

           _result.result(enum2str(InventAccountTypeSales::Dax));

           break;

       }

   }

   [SubscribesTo(tableStr(InventItemGroupForm), staticDelegateStr(InventItemGroupForm, getGroupForAccountTypeDelegate))]

   public static void inventItemGroupForm_getGroupForAccountTypeDelegate(InventAccountType _inventAccountType, EventHandlerResult _result)

   {

       switch (_inventAccountType)

       {

           case InventAccountType::Dax:

               _result.result(ItemGroupLedgerDimensionGroup::Sales);

               break;

       }

   }

//Method to stop the error which generates i.e., Enumerated text Daxarch does not exits

   [SubscribesTo(tableStr(InventPosting), staticDelegateStr(InventPosting, accountType2LedgerPostingTypeDelegate))]

   public static void inventPostingAccountTypeToLedgerPostingTypeDelegate(InventAccountType _inventAccountType, EventHandlerResult _result)

   {

       switch(_inventAccountType)

       {

           case InventAccountType::Dax:

               _result.result(LedgerPostingType::Dax);

               break;

       }

   }

}

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

Output:




Code to create Purchase Order ,Confirmation, Partial Product Receipt and partial Invoice in D365F&O X++

 public static void main(Args _args)

   {

       PurchPurchaseOrderHeaderV2Entity    purchPurchaseOrderHeaderV2Entity;

       PurchPurchaseOrderLineV2Entity      purchPurchaseOrderLineV2Entity;

       PurchFormLetter                     purchFormLetter;

       PurchFormletterParmData             purchFormLetterParmData;

       PurchParmUpdate                     purchParmUpdate;

       PurchParmTable                      purchParmTable;

       NumberSeq                           numberSeq;

       MarkupTrans                         markupTrans;

       PurchLine                           purchLine;

       SourceDocumentLine                  sourcedoucumentline;

       PurchParmLine                       purchParmLine;

       PurchTable                          purchTable;

       PurchId                             purchId;

       Num                                 packingSlipId;

 

       numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());

       numberSeq.used();

       

       purchPurchaseOrderHeaderV2Entity.initValue();

       purchPurchaseOrderHeaderV2Entity.PurchaseOrderNumber = numberSeq.num();

       purchPurchaseOrderHeaderV2Entity.PurchaseOrderName = "custom Order";

       purchPurchaseOrderHeaderV2Entity.OrderVendorAccountNumber = "1001";

       purchPurchaseOrderHeaderV2Entity.insert();

 

       purchPurchaseOrderLineV2Entity.PurchaseOrderNumber =  purchPurchaseOrderHeaderV2Entity.PurchaseOrderNumber;

       purchPurchaseOrderLineV2Entity.ItemNumber = '1000';

       purchPurchaseOrderLineV2Entity.PurchasePrice = 10;

       purchPurchaseOrderLineV2Entity.PurchasePriceQuantity = 2;

       purchPurchaseOrderLineV2Entity.OrderedPurchaseQuantity = 10;

       purchPurchaseOrderLineV2Entity.ReceivingSiteId = '1';

       purchPurchaseOrderLineV2Entity.ReceivingWarehouseId = '11';

       purchPurchaseOrderLineV2Entity.insert();

 

       purchId       = purchPurchaseOrderLineV2Entity.PurchaseOrderNumber;

       packingSlipId = "MA"+ purchId;

       purchTable    = PurchTable::find(purchId);

 

       select purchLine

           where purchLine.RecId == purchPurchaseOrderLineV2Entity.RecId;

 

       //creating a maintain charges record for line

       markupTrans.initFromMarkupTable(MarkupTable::find(MarkupModuleType::Vend,  "FREIGHT"));

       markupTrans.initFromPurchLine(purchLine);

       markupTrans.LineNum = MarkupTrans::lastLineNum(markupTrans.TransTableId, markupTrans.TransRecId)+1;

       markupTrans.modifiedField(fieldNum(markupTrans ,Value ));

       markupTrans.MarkupCode = "FREIGHT";

       markupTrans.Txt = "Freight";

       markupTrans.MarkupCategory = MarkupCategory::Fixed;

       markupTrans.Value = 200;

       markupTrans.MCROriginalMiscChargeValue = 200;

       markupTrans.CurrencyCode = "USD";

       markupTrans.ModuleType = MarkupModuleType::Vend;

       markupTrans.ModuleCategory = HeadingLine::Line;

       markupTrans.TransDate = today();

       markupTrans.insert();

 

       purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);

       purchFormLetter.update(purchPurchaseOrderHeaderV2Entity, strFmt("Inv_%1", purchPurchaseOrderHeaderV2Entity.PurchaseOrderNumber));

 

       ttsBegin;

       // Create PurchParamUpdate table

       purchFormLetterParmData = PurchFormletterParmData::newData(

       DocumentStatus::PackingSlip,

       VersioningUpdateType::Initial);

 

       purchFormLetterParmData.parmOnlyCreateParmUpdate(true);

       purchFormLetterParmData.createData(false);

       purchParmUpdate = purchFormLetterParmData.parmParmUpdate();

 

       //Set PurchParmTable table

       purchParmTable.clear();

       purchParmTable.TransDate                = SystemDateGet();

       purchParmTable.Ordering                 = DocumentStatus::PackingSlip;

       purchParmTable.ParmJobStatus            = ParmJobStatus::Waiting;

       purchParmTable.Num                      = packingSlipId;

       purchParmTable.PurchId                  = purchTable.PurchId;

       purchParmTable.PurchName                = purchTable.PurchName;

       purchParmTable.DeliveryName             = purchTable.DeliveryName;

       purchParmTable.DeliveryPostalAddress    = purchTable.DeliveryPostalAddress;

       purchParmTable.OrderAccount             = purchTable.OrderAccount;

       purchParmTable.CurrencyCode             = purchTable.CurrencyCode;

       purchParmTable.InvoiceAccount           = purchTable.InvoiceAccount;

       purchParmTable.ParmId                   = purchParmUpdate.ParmId;

       purchParmTable.insert();

 

       // Set PurchParmLine table

       while select purchLine

       where purchLine.PurchId == purchTable.purchId

       {

           purchParmLine.InitFromPurchLine(purchLine);

 

           purchParmLine.ReceiveNow    = 5;//PurchLine.PurchQty;

           purchParmLine.ParmId        = purchParmTable.ParmId;

           purchParmLine.TableRefId    = purchParmTable.TableRefId;

           purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);

           purchParmLine.setLineAmount();

           purchParmLine.insert();

       }

 

       purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);

       purchFormLetter.transDate(systemDateGet());

       purchFormLetter.proforma(false);

       purchFormLetter.specQty(PurchUpdate::All);

       purchFormLetter.purchTable(purchTable);

 

       // This is the ID we hard code as the product receipt ID, if we do the posting via UI

       // user would have the option to manually enter this value

       purchFormLetter.parmParmTableNum(purchParmTable.ParmId);

       purchFormLetter.parmId(purchParmTable.ParmId);

       purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());

       purchFormLetter.run();

       ttsCommit;

       

       //posting of invoice

       purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);

       purchFormLetter.update(purchTable, "Inv_"+purchTable.PurchId,systemdateget(),PurchUpdate::PackingSlip); // Transaction date

       info(purchTable.PurchId);

   }

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









            




Thursday, April 4, 2024

How to use strSplit() Function in x++

public static void main(Args _args)

   {

       str no = "D0001-1.0";

       ListIterator iterator;

       List strlist=new List(Types::String);

       str beforeDec,afterDec,finalOutput;

       int x;

 

       strlist=strSplit(no,"-");

       iterator = new ListIterator(strlist);

       

       while(iterator.more())

       {

           x= x+1;

           if(x==1)

           {

               beforeDec =iterator.value();

           }

           if(x==2)

           {

               afterDec = iterator.value();

           }

           iterator.next();

       }

       Info(strFmt("%1,%2",beforeDec,afterDec));

   }

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



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: