Thursday, May 26, 2022

How to create field Id lookup in D365FO

Hi D365FO Team,


I am creating another blog here to know how to create table field Id Lookup.

Requirement - Show all VendTable field in lookup.

Solution/Steps

1) Create temprary table as shown in below screen with 2 fields.
Table name - TestFieldsListPreviewTMP
FieldName - use EDT fieldnameShort
FieldId  - use EDT Integer

Set Property - TableType = InMemory
Create Primary index on FieldId

2) Create new table TestLookupDSTable for formDatasource where you want to show table field lookup.















Add methods in above table-

Create lookupFields() method to insert all the field list from table buffer.

public static TestFieldsListPreviewTMP  lookupCustomFields(Common   _common)
{
        var dictTable = new DictTable(_common.TableId);
        FieldId fieldId = dictTable.fieldNext(0);

        TestFieldsListPreviewTMP  fieldListPreview;

        while (fieldId && ! isSysId(fieldId))
        {
            fieldListPreview.FieldId = fieldId;
            fieldListPreview.FieldName = fieldId2PName(_common.tableId, fieldId);
            fieldListPreview.insert();
            fieldId = dictTable.fieldNext(fieldId);
        }
        return fieldListPreview;
}

public static void performLookup(Common _common, FormControl _formControl)
{

     SysTableLookup sysTableLookup =         SysTableLookup::newParameters(tablenum(TestFieldsListPreviewTMP), _formControl);

        Query query = new Query();
        QueryBuildDataSource queryBuildDataSource;
        queryBuildDataSource = query.addDataSource(tablenum(TestFieldsListPreviewTMP));
        queryBuildDataSource.addSortField(fieldNum(TestFieldsListPreviewTMP, FieldId), SortOrder::Ascending);

        sysTableLookup.addLookupfield(fieldnum(TestFieldsListPreviewTMP, FieldId), true);
        sysTableLookup.addLookupfield(fieldnum(TestFieldsListPreviewTMP, FieldName));
        sysTableLookup.parmQuery(query);

        TestFieldsListPreviewTMPfieldListTMP;

        fieldListTMP = TestForDataSourceTable::lookupCustomFields(_common);

        //TestVend2CustMapping is a form data source table.
        sysTableLookup.parmTmpBuffer(fieldListTMP);
        sysTableLookup.performFormLookup();

    }

//Populate field name 
public static FieldName predictFieldName(TableId _tableId, FieldId _fieldId)
{
        return fieldId2PName(_tableId, _fieldId);
}

public void modifiedField(FieldId _fieldId)
{
        super(_fieldId);
        switch(_fieldId)
        {
            case (fieldNum(TestLookupDSTable,FieldIdVend )) :           
                this.FieldNameVend = TestLookupDSTable::predictFieldName(tableNum(VendTable), this.FieldIdVend);             

                break;
            default:

        }
}


3) Create new form and add TestLookupDSTable as data source and override datasource field lookup method and write below code.















public void lookup(FormControl _formControl, str _filterStr)
{
     VendTable   vendTable;

     TestLookupDSTable::performLookup(vendTable, _formControl);

}


Result - 






Friday, May 20, 2022

Create offset ledger dimension using mainaccount id and defaultdimension in D365FO

Hi All,
In this blog we will learn how to create ledger dimension using main account and default dimension RecId.  


X++ Code


public static RecId getLedgerDimensionFromDefaultDimension(MainAccountNum _mainAccountId,     RecId _defaultDimension)

    {
        MainAccount     mainaccount = MainAccount::findByMainAccountId(_mainAccountId);
        RecId           ledgerddimension;
        ledgerddimension =     LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountId(_mainAccountId), _defaultDimension);

        return ledgerddimension;

    }



Regards,

Vijay Yelmame

vijay.yelmame@2019@gmail.com



How to get Default dimensions from ledger dimensions in D365FO

 Hi All,
This blog will explain you how to get default dimension from ledger dimension by using standard methods. by using LedgerDimensionFacade class we can easily get it.


X++ Code

DimensionDefault defaultDimension = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(ledgerJournalTrans.LedgerDimension);

Thursday, May 19, 2022

x++ code to get all selected records from form datasource or Grid

Hi All,
In this blog we will learn how to get all selected records from form grid or form datasource in event handler.    

X++ code.

[FormControlEventHandler(formControlStr(LedgerJournalTransCustPaym, UpdateOffsetDimension), FormControlEventType::Clicked)]

public static void UpdateOffsetDimension_OnClicked(FormControl sender, FormControlEventArgs e)
{
        FormRun                 formRun     = sender.formRun();
        FormDataSource          ledgerJournalTrans_ds;
        LedgerJournalTrans      ledgerJournalTrans;        
        ledgerJournalTrans_ds = formRun.dataSource(tableStr(LedgerJournalTrans));

        MultiSelectionHelper    selectionHelper = MultiSelectionHelper::construct(); 

        selectionHelper.parmDataSource(ledgerJournalTrans_ds); 

        ledgerJournalTrans = selectionHelper.getFirst();

        while (ledgerJournalTrans)
        {
            info(ledgerJournalTrans.Voucher);
            ledgerJournalTrans = selectionHelper.getNext();
        }
}

Modify email subject and body of Print Payment Advice email generated by Print Management

Hi all,
In this blog will learn how to modify the standard email subject and body generated through the Print Management.    

Requirement - 
1) Add vendor code in Subject line.
2) Modify email body - add vendor name and Legal entity name.

This can be achieve by doing small customization.

Solution/Steps

1) Create extension class for class - SRSPrintDestinationSettings and add below code.

[ExtensionOf(classstr(SRSPrintDestinationSettings))]
public final class TestSRSPrintDestinationSettings_Extension
{
    internal    str     reportTitle;
    internal    RecId   voucherRecId;
    //Type of report
    [DataMemberAttribute]
    public str reportTitle(str _reportTitle = reportTitle)
    {
        reportTitle = _reportTitle;
        return reportTitle;
    }
     [DataMemberAttribute]
    public RecId voucherRecId(RecId _voucherRecId = voucherRecId)
    {
        voucherRecId = _voucherRecId;
       return voucherRecId;
    }

  public SrsReportEMailDataContract parmEMailContract(SrsReportEMailDataContract _emailContract)

    {

        Notes                                       emailBOdy;
        SrsReportEmailDataContract  contract;
        LedgerJournalTrans              ledgerJournalTrans; 
        contract = next parmEMailContract(_emailContract);
        if (reportTitle == "Payment Advice")
        {

             emailSubject =     contract.parmSubject();
            select firstonly ledgerJournalTrans  where ledgerJournalTrans.RecId == voucherRecId;

            emailSubject =  strReplace(emailSubject,"%VendorAccount%",                                                                 ledgerJournalTrans.accountDisplay());

            contract.parmSubject(emailSubject);            

            emailBOdy = VendParameters::find().MTEmailBodyForPaymentAdvice;

            emailBOdy = strReplace(emailBOdy,"%VendorName%",ledgerJournalTrans.LedgerDimensionName);

        emailBOdy =             strReplace(emailBOdy,"%LegalEntityName%",CompanyInfo::findRecId(CompanyInfo::current()).Name);

            contract.parmBody(emailBody);    

        }
        return contract;

    }

}
Step 2 : Create COC for printReport() method of class SrsReportRunPrinter

[ExtensionOf(classStr(SrsReportRunPrinter))]
public final class TestSrsReportRunPrinter_extension
{
    public void printReport()
    {
        if (reportContract.parmRdpName() == "BankPaymAdviceVendDP")
        {
            BankPaymAdviceContract bankPaymAdviceContract = reportContract.parmRdpContract() as                 BankPaymAdviceContract;
            printSettings.reportTitle("Payment Advice");
            printSettings.voucherRecId(bankPaymAdviceContract.parmLedgerJournalTransRecId());
        }
        next printReport();
        }
}

Step 3 : Add new field for email template in AP parameter(VendParameter)

and paste below content 

Dear Sir's
<br>
Regarding payment to: %VendorName%
<br>
Please refer the attached payment advice.
<br>
Yours faithfully
<br>
%LegalEntityName%






  



 



Step 4 : Add setup in Print management 

Refer below highlighted path 














































Result -










Saturday, March 19, 2022

How to add custom range method to apply range on View.

Hi All,
In this blog will learn how to add range method same as  SysQueryRangeUtil methods and apply on view.

Requirement - Add range in view to take only records up to last month ( Today() – days of current date)  i.e equal to up to last month transactions

Solution -  Create new class and add method according to the range and copy method attribute [QueryRangeFunction]

x++ Code
public static class TestVoyageClass
{
 [QueryRangeFunction]
public static str lessthanLastMonth()
{
int days ;
utcdatetime currentDateTime;
currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());
days = DateTimeUtil::day(currentDateTime)-1;
return SysQueryRangeUtil::lessThanDate(-days);
}
}
Add method name in range property of view. 


 







Thats It !!

How to ignore error in Finance and Operation


Dear  AX/D365FO Team,

Today we are going to learn how to ignore known errors in D365FO.
Recently I came to this situation where I have no choice rather than ignore the error and continue the build. So lets start and understand the situation when we need to ignore the errors.

Requirement : Show lookup in excel add-in for custom dimensions.


Solution :Add related field fix relation with string value (dimensions name).Normally this is not allowed in D365FO but we can achieve this through ignore error functionality. 

Development :
As you can see in below screen CD1 is my string value in related field fix relation, x++ is not allowing you to create related field fix relation on the basis of string values. To achieve this I have used ignore error functionality.

  


Steps to ignore Error-
1) After making such changes start building of your model.
    once you complete your model build you will get one error file generated in below path 

2) Next you need to rename it as CompileError.xml
and change first Tag name of xml file from <Diagnostics></ Diagnostics > to <IgnoreDiagnostics> </IgnoreDiagnostics>

And keep this file in below location – and do the build.












3) Build the model again and check the result.

Error file format 

<Diagnostic>
<DiagnosticType>Metadata</DiagnosticType>
<Severity>Error</Severity>
<Path>AxDataEntityViewExtension/DimensionCombinationEntity.MT/Relations/CD1/Constraints/RelationConstraintRelatedFixed1/RelatedField</Path>
<Moniker>FieldTypeIsEnumOrInt</Moniker>
<Message>Field type must be enum, int, or int64.</Message>
</Diagnostic>
<Diagnostic>
<DiagnosticType>Metadata</DiagnosticType>
<Severity>Error</Severity>
<Path>AxDataEntityViewExtension/DimensionCombinationEntity.MT/Relations/CD1/Constraints/RelationConstraintRelatedFixed1/Value</Path>
<Moniker>RelationConstraintValueStrMalformed</Moniker>
<Message>The value must be an integer or the enum value in the format: &lt;enumname&gt;::&lt;enumvaluename&gt;.</Message>
</Diagnostic>





Update Values During Data Entity Import in D365FO

Update Values During Data Entity Import in D365FO Updating Field Values During Data Entity Import in Dynamics 365 Finance ...