Wednesday, August 23, 2023

Code to change the Electronic payment format of vendor payment journal in D365 F&O

 My requirement is to change the exported format(NACHA) of vendor payment journal.

Standard Format (Existing):

AP>Vendor payment journal>lines>generate payements.



Code to modify the existing format :


[ExtensionOf(classStr(VendOutPaym_NACHA))]

internal final class DaxvendOutPaym_NACHA_Extension

{

   public LedgerJournalTrans  ledgerJournalTrans;

   protected container createACH_HeaderRecord()

   {

       LogisticsPostalAddress  logisticsPotalAddress;

       container   headerACH,con;

       str         value = "HD";

       str         value2,dateValue,value3,datevalue2,effectivedateloc,journalnum,amountcurdebit,accountid,vendorid;

                 

       #define.spc(' ')

       str 50      aditonalname            =   strRep(#spc, 50); //to get spaces of length 50

       value3      = "PYCHK";

       dateValue   = date2str( systemDateGet(),

                       321,

                       DateDay::Digits2,

                       DateSeparator::Hyphen,

                       DateMonth::Digits2,

                       DateSeparator::Hyphen,

                       DateYear::Digits4,

                       DateFlags::FormatAll);

       effectivedateloc = date2str( effectiveEntDate,

                       321,

                       DateDay::Digits2,

                       DateSeparator::Hyphen,

                       DateMonth::Digits2,

                       DateSeparator::Hyphen,

                       DateYear::Digits4,

                       DateFlags::FormatAll);

 

       headerACH = next createACH_HeaderRecord();

       CompanyInfo     companyInfo = CompanyInfo::find();

       //while

       select ledgerJournalTrans where ledgerJournalTrans.JournalNum == ledgerJournalId;

       vendorid = LedgerDimensionFacade::getDisplayValueForLedgerDimension(ledgerJournalTrans.LedgerDimension);

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           select logisticsPotalAddress

           where logisticsPotalAddress.Location == ledgerJournalTrans.RemittanceLocation;

           //{

           value2 = ledgerJournalTrans.PaymReference;

           if(ledgerJournalTrans.AmountCurCredit)

           {

               value3 = value3 + "C";

           }

           if(ledgerJournalTrans.AmountCurDebit)

           {

               value3 = value3 + "D";

           }

           datevalue2 = date2str( ledgerJournalTrans.TransDate,

                       321,

                       DateDay::Digits2,

                       DateSeparator::Hyphen,

                       DateMonth::Digits2,

                       DateSeparator::Hyphen,

                       DateYear::Digits4,

                       DateFlags::FormatAll);

           amountcurdebit = strRFix(any2Str(ledgerJournalTrans.AmountCurDebit),16,'0');

           // }

           value2 = strRFix(value2,15,'0');

           journalnum = strLFix(ledgerJournalId,30,' ');

           accountid = strLFix(bankAccountTable.AccountID,35,' ');

 

           headerACH = conNull();

           con = conIns(headerACH,1,value + value2 + dateValue + "\n" + value3 + journalnum

                   + datevalue2 + effectivedateloc + effectivedateloc + amountcurdebit + "." + any2Str(ledgerJournalTrans.AmountCurDebit));

           return con;

       }

       else

       {

           return headerACH;

       }   

   }

   protected container createBatchHeaderRecord()

   {

       container   headerBatch;

       headerBatch =  next createBatchHeaderRecord();

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           headerBatch = conNull();

           return headerBatch;

       }

       else

       {

           return headerBatch;

       }

   }

   protected container createBatchControlRecord()

   {

       container   headerBatch;

       headerBatch = next createBatchControlRecord();

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           headerBatch = conNull();

           return headerBatch;

       }

       else

       {

           return headerBatch;

       }

   }

 

   protected container createACH_ControlRecord()

   {

       container   headerBatch;

       container  contai;

       str  con = "lohith";

       headerBatch = next createACH_ControlRecord();

       if(ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::None)

       {

           headerBatch = conNull();

           return headerBatch;

       }

       else

       {

           return headerBatch;

       }

   }

}

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

[ExtensionOf(classstr(VendOutPaymRecord_NACHA_CCD))]

internal final class DaxVendOutpaymRecord_NACHA_CCD_Extension

{

   protected void initRecord()

   {

       next initRecord();

       outputRecord = "";

   }

}


OutPut :








Monday, August 7, 2023

Code to get the Voucher transactions from purchase order receipts

 

public static void main(Args _args)

   {

       GeneralJournalAccountEntry      generalJournalAccountEntry;

       GeneralJournalEntry             generalJournalEntry;

 

       while select generalJournalEntry

           where generalJournalEntry.DocumentNumber == "1234" //product receipt number

           && generalJournalEntry.AccountingDate == mkDate(07,08,2023) //delivery date

       {

           while select generalJournalAccountEntry

                    where generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId

           {

               info(strFmt("Voucher : %1,Accounitng Currency Amount : %2,Journal num : %3",generalJournalEntry.SubledgerVoucher,generalJournalAccountEntry.AccountingCurrencyAmount,generalJournalEntry.JournalNumber));

 

           }

       }        

   }

Output :




Other Way:

https://jaipaljadav11.blogspot.com/2023/08/tables-involved-while-opening-voucher.html




Friday, August 4, 2023

Code to Populate Custom field data from PurchTable to PurchParmtable in D365 X++

    [ExtensionOf(classStr(PurchFormletterParmData))]

   internal final class DaxPurchFormLetterParmData_Extension

   {

       protected VendDocumentTableMap initializeParmTable(

      VendDocumentTableMap  _parmTable,

      PurchLine             _purchLine,

      PurchTable            _purchTable,

      TradeLineRefId        _tableRefId,

      boolean               _hold,

      boolean               _notApproved ,

      Num                   _purchSummaryFormLetterId,

      VendPostingProfile    _postingProfile ,

      InventProfileType_RU  _inventProfileType

     )

       {

           VendDocumentTableMap map = next initializeParmTable(_parmTable,

                                                         _purchLine,

                                                         _purchTable,

                                                          _tableRefId,

                                                          _hold,

                                                          _notApproved ,

                                                          _purchSummaryFormLetterId,

                                                          _postingProfile ,

                                                         _inventProfileType);

 

           PurchParmTable  purchParmTable  = _parmTable;

           purchParmTable.UserName = _purchTable.UserName;

           return map;

       }

   }

........

Output :




Other Way :

    [ExtensionOf(classstr(PurchFormLetter))]

   internal final class Dax_formLetterParmData_Extension

   {

       public void chooseLines(boolean _processAdditional,

                          VendDocumentTableMap _parmTable,

                          boolean _append)

       {

           PurchParmTable purchParmTable;

           PurchTable purchTable;

 

           next chooseLines(_processAdditional , _parmTable,_append );

 

           select forupdate purchParmTable where purchParmTable.RecId == this.parmLastParmTableRecId();

           purchTable = purchTable::find(purchParmTable.PurchId);

           ttsbegin;

           purchParmTable.DaxStatus = purchTable.DaxStatus;

           purchParmTable.update();

           ttscommit;

       }

   }






Wednesday, August 2, 2023

Code to get Table Fields and Fieldcount in D365 X++

 

public static void main(Args _args)

   {

       dictTable   dt;

       DictField   df;

       int         numberOfFields,fieldId,i;

 

       dt = new dictTable(tablename2id("DaxTable"));

       numberOfFields = dt.fieldCnt();

       for (i = 1; i <= (numberOfFields); i++)

       {

           fieldId = dt.fieldCnt2Id(i);

           df = dt.fieldObject(fieldId);

           info(df.label());

       }

   }

Output :








Code to get user's assigning roles and removing roles in d365 X++

 My requirement is to get the user assigned roles and removed roles information.

In details :

I'm a Admin user . I've added few roles to a user named "ARNIE".

Added Roles :


Removed Roles :

Removed  the above added one role "Time registration user role".



Code to get the Added Roles :

[ExtensionOf(formcontrolstr(syssecuseraddroles,commandButtonOK))]

internal final class DaxSyssecAddRoles_Extension

{

   public void clicked()

   {

       SecurityRole                 securityRole;

       DaxRoleAssignmentInfoLog     daxRolesAssignmentinfoLog;//custom table.

       UserInfo                     userInfo;

       MultiSelectionHelper         helper;

       SecurityUserRole             securityUserRole;

       FormControl                  callerButton    = any2Object(this) as FormControl;

       FormRun                      formRun         = callerButton.formRun();

       FormDataSource               formDataSource  = formRun.datasource(1);

       if (element.args().dataset() == tableNum(UserInfo))

       {

           userInfo  = element.args().record();

       }

       next Clicked();

       securityRole = formDataSource.getFirst(true);

       while(securityRole)

       {

           ttsbegin;

           daxRolesAssignmentinfoLog.ChangedBy     = curUserId();

           daxRolesAssignmentinfoLog.UserId        = userInfo.id;

           daxRolesAssignmentinfoLog.AssignedRole  = securityRole.Name;

           daxRolesAssignmentinfoLog.SecRecId      = securityRole.recid;

           daxRolesAssignmentinfoLog.Organisation  = curExt();

           daxRolesAssignmentinfoLog.insert();

           ttscommit;

           securityRole = formdataSource.getNext();

       }

   }

}

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

Code to get current removing role record :

[ExtensionOf(classstr(SysUserInfoManagementForm))]

internal final class Dax_SysUserInfoManagementForm_Extension

{

  public static SysSecRole selectedRoleloc;

   public void TreeRolesSelectionChanged(FormTreeItem _newItem)

   {

       

       next TreeRolesSelectionChanged(_newItem);

       selectedRoleloc = tree.getData(_newItem);

   }

   public static  SysSecRole parmSysSecRole()

   {

       return selectedRoleloc;

   }

}

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

Code to update the custom table when role is removed :

[ExtensionOf(formControlStr(SysUserManagement,btnUserRoleRemove))]

public final class DaxSysSecAddUser_Extension

{

   public void clicked()

   {

       SysSecRole                      secRole;

       DaxRoleAssignmentInfoLog        daxRoleAssignmentInfoLog;

       secRole = SysUserInfoManagementForm::parmSysSecRole();

       next  clicked();

       select forupdate daxRoleAssignmentInfoLog

           where daxRoleAssignmentInfoLog.SecRecId == secRole.getRecId();

       if(daxRoleAssignmentInfoLog)

       {

           ttsbegin;

           daxRoleAssignmentInfoLog.RemovedRole = daxRoleAssignmentInfoLog.AssignedRole;

           daxRoleAssignmentInfoLog.AssignedRole = "";

           daxRoleAssignmentInfoLog.update();

           ttscommit;

       }

   }

}

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


Output :