Wednesday, 4 January 2023

Display max end time of the day using X++

 

In this post we will see how we can display a maximum end time of the day. For instance if I want to show the max end time of today which will be 11:59:59 PM. We can use newDateTime() method of DateTimeUtil class and will use the seconds to adjust our time.

 

MyTable myTable;
TimeOfDay secondsElapsed;
secondsElapsed = 86399;

myTable.ToDateTime = DateTimeUtil::newDateTime(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()),secondsElapsed);

 

This will result you the system date with end time 11:59:59PM.

Form data source modified field event handler in D365FO

 

Below code shows how to get buffer from form data source field event handler(modified field) and update values as per the requirement


/// <summary>
/// Logic that displays the end time of the day
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormDataFieldEventHandler(formDataFieldStr(BankStatementTable,
BankStmtISOAccountStatement, ToDateTime),
FormDataFieldEventType::Modified)]
public static void ToDateTime_OnModified(FormDataObject sender,
FormDataFieldEventArgs e)
{
    FormDataSource BankStmtISOAccountStatement_ds =
    sender.datasource();
    BankStmtISOAccountStatement bankStmtISOAccountStatement =
    BankStmtISOAccountStatement_ds.cursor();
    TimeOfDay secondsElapsed;
    secondsElapsed = 86399;
    if(!bankStmtISOAccountStatement.ToDateTime)
    {
      bankStmtISOAccountStatement.ToDateTime =
      DateTimeUtil::newDateTime(DateTimeUtil::getSystemDate
     (DateTimeUtil::
      getUserPreferredTimeZone()),
      secondsElapsed);
    }
    else
    {
      bankStmtISOAccountStatement.ToDateTime = 
      DateTimeUtil::newDateTime(DateTimeUtil::date
      (bankStmtISOAccountStatement.ToDateTime),
      secondsElapsed);
    }
}

Query that returns primary contacts of customer

 

Sometimes we need to get the primary details of a customer. Below SQL query provides the primary email information of the customer. Depending on contact type, we can get the details. If we comment the type condition, query will return all the primary contact information.

1
2
3
4
5
6
7
8
9
10
11
12
select LogisticsElectronicAddress.locator,
LogisticsElectronicAddress.TYPE,
LogisticsElectronicAddress.ISPRIMARY,* from custtable
JOIN DirPartyLocation
ON dirPartyLocation.party = custtable.Party
JOIN LogisticsElectronicAddress
ON LogisticsElectronicAddress.Location =
dirPartyLocation.Location
AND LogisticsElectronicAddress.Type = 2
AND LogisticsElectronicAddress.ISPRIMARY = 1
JOIN LogisticsElectronicAddressRole
ON LogisticsElectronicAddressRole.ElectronicAddress =
LogisticsElectronicAddress.RecId
join LogisticsLocationRole
ON LogisticsLocationRole.RecId =
LogisticsElectronicAddressRole.LocationRole
where custtable.AccountNum = "CustAccount"

Sample UI builder class with registerOverride() method

 

This blog demonstrates how to use the registerOverride() method in the UIBuilder class to dynamically enable or disable dialog fields, such as date ranges, based on user input.


class myUIBuilder extends SrsReportDataContractUIBuilder
{

    DialogField dlgIsManually;
    DialogField dlgFromDate;
    DialogField dlgToDate;
    myContract contract;


    public void postBuild()
    {
         super();
         contract = this.dataContractObject() as myContract;

         dlgfromdate =                                     this.bindinfo().getdialogfield(contract,

         methodstr(myContract,parmFromDate));
         dlgtodate this.bindinfo().getdialogfield(contract,methodstr

         (myContract,parmToDate));

         dlgIsManually =               this.bindInfo().getDialogField(contract,methodStr            (myContract,parmIsManually));

     //By default these controls will be disabled when parameter form loads first time

       dlgFromDate.enabled(false);
        dlgToDate.enabled(false);

        if (dlgIsManually.value() == NoYes::Yes)
        {
            dlgFromDate.enabled(true);
            dlgToDate.enabled(true);
        }


        //disableDataRange() method attached with modified event of dlgIsManually             control so //this will call whenever dlgIsManually is modified

        dlgIsManually.registerOverrideMethod(methodstr(

        FormCheckBoxControl,modified),            methodstr(myUIBuilder,                     disableDateRange),this);

}


/// Disables date range based on checkbox selection


public boolean disableDateRange(FormCheckBoxControl _isManually)
{
    boolean returnValue;

    returnValue = _isManually.modified();

    dlgFromDate.enabled(true);
    dlgToDate.enabled(true);

    if (returnValue && dlgIsManually.value() == NoYes::No)
    {
        dlgFromDate.enabled(false);
        dlgToDate.enabled(false);    
    }

    return returnValue;
    }

}

UIBuilder provides a powerful way to customize and control parameters by manipulating dialog fields at runtime. 

By using the registerOverride() method in UIBuilder, you can control the behavior of dialog fields in a parameter form dynamically.

Filtering Company-Specific Product Templates - SysRecordTmpTemplate lookup

Hi Techies - Recently I have come across a requirement where I needed to display product templates specific to a selected company for a give...