Tuesday, February 4, 2025

Code to get workflow assignee in X++

     public UserId getWorkflowAssignee()

    {

        WorkflowTrackingStatusTable workflowTrackingStatusTable;

        WorkflowWorkItemTable workflowWorkItemTable;

        UserInfo userInfo;

        UserId ret;

 

        select firstonly workflowWorkItemTable

            where workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem

                && workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending

            join workflowTrackingStatusTable

                where workflowWorkItemTable.CorrelationId == workflowTrackingStatusTable.CorrelationId

                    && workflowTrackingStatusTable.ContextTableId == this.TableId //your table id

                    && workflowTrackingStatusTable.ContextRecId == this.RecId 

                    && workflowTrackingStatusTable.TrackingStatus == WorkflowTrackingStatus::Pending

            join userInfo

                where workflowWorkItemTable.UserId == userInfo.id;

 

        if (workflowWorkItemTable.RecId)

        {

            ret = userInfo.id;

        }

        return ret;

    }

Workflow step name x++

I need to fetch the name of the "Step" of the workflow. 

For example:

In my workflow,  step1 : approved by teamlead (name of step)

step2: approved by manager (name of step)

so, I need to show the name i.e: approved by teamleader


public display Description currentStep()
{
    WorkflowTrackingTable             trackingTable;
    WorkflowTrackingStatusTable       trackingStatusTable;

    select RecId, User,Name, CreatedDateTime from trackingTable
    order by CreatedDateTime desc where
     trackingTable.TrackingType == WorkflowTrackingType::Creation &&
     trackingTable.TrackingContext == WorkflowTrackingContext::Step
    join trackingStatusTable
    where trackingTable.WorkflowTrackingStatusTable == trackingStatusTable.RecId &&
        trackingStatusTable.ContextRecId == this.RecId &&
        trackingStatusTable.ContextTableId == this.TableId;

    return trackingTable.Name;

}

Thursday, January 30, 2025

Error

 



I'm getting the above error "when a purchase order is released and then if i modify any field in form and click on save"

Resolution :

Refresh the main and line data sources in write method of main data source. And re read the main data source.
Refreshed the data sources in Release order button also. 

Wednesday, January 15, 2025

Working with date functions

 

1. How to get current date in dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function today() is used to get the current date from the given date in dynamics 365 finance and operations,This function returns the current date that is used by the client. 

Here i have created one runnable class DateFunctionsJob. Once you created the class , you can copy and paste the below codes as per your requirements.

Ezoic

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {
       Transdate dateToday ;     
dateToday = today();
info(strfmt("Date- %1",dateToday));
}
}


Output :
Date - 7/22/2023

2. How to gets the Month Number from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function mthofYr(mydate) is used to get the Month Number from the given date in dynamics 365 finance and operations,This function returns the Month Number that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;   
int monthNumber;
       dateToday = today();
       monthNumber=mthofYr(dateToday);
       info(strfmt("Month Number - %1",monthNumber));    
}


Output :
Month Number- 7

3. How to gets the Month Name from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function mthname(mthofYr(mydate)) is used to get the Month Name from the given date in dynamics 365 finance and operations,This function returns the Month Name that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;  
str monthName ;
dateToday = today();
       monthName = mthname(mthofYr(dateToday));    
       info(strfmt("Month Name - %1",monthName));     
}


Output :
Month Name - July

4. How to gets the Day Number from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayOfMth() is used to get the Day Number from the given date in dynamics 365 finance and operations,This function returns the Day Number that is used by the client.
public static void main(Args _args)
   {
       Transdate dateToday;
       int dayNumber;
       dateToday = today();
       dayNumber = dayOfMth(dateToday);     
       info(strfmt("Day Number- %1",dayNumber));      
  }

Output :
Day Number - 22

5. How to gets the Day Name from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayname(dayOfMth(mydate)) is used to get the Day Name from the given date in dynamics 365 finance and operations,This function returns the Day Name that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       str dayName;
dateToday = today();
       DayName = dayname(dayOfMth(dateToday));   
  info(strfmt("Day Name - %1",dayName));
}


Output :
Day Name - Saturday

6. How to get the year from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function year(mydate) is used to get the year from the given date in dynamics 365 finance and operations,This function returns the year that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;   
int year ;
       dateToday = today();
       Year =year(dateToday);
       info(strfmt("Year - %1",year));   
}


Output :
Year - 2023

7. How to gets the week day number from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayOfwk(mydate) is used to get the week day number from the given date in dynamics 365 finance and operations,This function returns the week day number that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       int weekDayNumber;
dateToday = today();
       weekDayNumber= dayOfwk(dateToday);   
  info(strfmt("Week Day Number - %1",weekDayNumber));
}

Ezoic


Output :
Week Day Number - 6

8. How to gets the day of year from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayOfyr(mydate) is used to get the day of year from the given date in dynamics 365 finance and operations,This function returns the day of year that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       int dayOfYear;
dateToday = today();
       dayOfYear= dayOfyr(dateToday);   
  info(strfmt("Day of year - %1",dayOfYear));
}


Output :
Day of year - 203

9. How to get week of the year from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function wkofyr(mydate) is used to get the week of the year from the given date in dynamics 365 finance and operations,This function returns the week of the year that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       int weekOfYear;
dateToday = today();
       weekOfYear= wkofyr(dateToday);   
  info(strfmt("Week of the year - %1",weekOfYear));
}


Output :
Week of the year - 29

Wednesday, January 8, 2025

Create the LedgerDimension RecId from Mainaccount and the default dimension RecId using X++ in D365FO

 LedgerDimensionFacade::serviceCreateLedgerDimension

(LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId

(MainAccount::findByMainAccountId(_mainAccountId).RecId),

defaultDimensionRecId);


Main account and financial dimensions combination should be configuared

How to get MainAccount using ledger dimension recId in ax 2012


Table.MainAccountId             =   MainAccount::findByLedgerDimension(ledgerDimension).MainAccountId;

Tuesday, December 17, 2024

Code to auto submit the workflow in D365f&o x++

 WorkflowVersionTable workflowVersionTable = Workflow::findWorkflowConfigToActivateForType(workFlowTypeStr(ProjBudgetRevision),


                                                                             projBudRevision.RecId,


                                                                             projBudRevision.TableId);

            //If workflow is active then submit the workflow.

            if (projBudRevision.RecId && workflowVersionTable.RecId)

            {

                //submitting to workflow

                Workflow::activateFromWorkflowType( workFlowTypeStr(ProjBudgetRevision),

                                                projBudRevision.RecId,

                                                "@AutomaticWorkflowSubmit",

                                                false,

                                                curUserid());

                //Update revison workflow status to submit

                ProjBudgetRevision::updateProjBudgetRevisionStatus(projBudRevision.RecId, ProjBudgetRevisionWFStatus::Submitted);

            }

Wednesday, August 7, 2024

How to Copy Custom Fields Throughout the Purchase Order Process in D365 F&O Using X++

 A new custom field has been added to the Purchase Order (PO) header in Dynamics 365 Finance & Operations. This field must be automatically carried forward throughout the entire procurement lifecycle to ensure visibility and consistency across related documents and journal records. Specifically, the custom field should be copied to the following procurement artifacts:

  • Purchase Order Confirmation

  • Purchase Order Confirmation Journals

  • Product Receipt

  • Product Receipt Journals

  • Purchase Invoice

  • Purchase Invoice Journals


Purchase Order Header :




Purchase Order Confirmation & Product Receipt

[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);

  

       if(this.parmDocumentStatus() != DocumentStatus::Invoice)

       {

           PurchParmTable  purchParmTable  = _parmTable;

           purchParmTable.DaxComment = _purchTable.DaxComment;

       }    

       return map;

   }

}





Purchase Order Confirmation Journals

[ExtensionOf(classStr(PurchPurchOrderJournalcreate))]

internal final class DaxPurchPurchOrderJournalcreate_Extension

{

   /// <summary>

   /// Initializes the journal header record.

   /// </summary>

   protected void initJournalHeader()

   {

       next initJournalHeader();

       vendPurchOrderJour.DaxComment = purchParmTable.DaxComment;

   }

}

field is modified and confirmed.



Product Receipt Journals 

[ExtensionOf(Classstr(PurchPackingSlipJournalCreate))]

internal final class DaxPurchPackingSlipJournalCreate_Extension

{

   /// <summary>

   /// Initializes non-correctable fields on the journal header.

   /// </summary>

   public void initHeader()

   {

       next initHeader();

       vendPackingSlipJour.DaxComment = purchParmTable.DaxComment;

   }

}

Custom field is modified and product receipt is posted.



Purchase Invoice

[ExtensionOf(classStr(PurchFormletterParmDataInvoice))]

internal final class DaxPurchFormLetterParmDataInvoice_Extension

{

   protected void insertParmTable(Common _vendInvoiceInfoTable)

   {

       VendInvoiceInfoTable  vendInvoiceInfoTable = _vendInvoiceInfoTable;

       PurchTable            purchTable;

 

       select purchTable

           where purchTable.PurchId == vendInvoiceInfoTable.PurchId;

 

       vendInvoiceInfoTable.DaxComment = purchTable.DaxComment;

       _vendInvoiceInfoTable = vendInvoiceInfoTable;

 

       next insertParmTable(_vendInvoiceInfoTable);   

   }

}



Purchase Invoice Journals

[ExtensionOf(classStr(PurchInvoiceJournalCreate))]

internal final class DaxPurchInvoiceJournalCreate_Extension

{

   protected void initJournalHeader()

   {

       next initJournalHeader();

       vendInvoiceJour.DaxComment = vendInvoiceInfoTable.DaxComment;

   }

}

Field is modified to "Test invoice" and invoice is posted.