Friday, October 7, 2022

Globals in D365FO (Implementation samples)

Samples


/// <summary>

    /// Convert the date input value to the string format YYYYMMDD.

    /// </summary>

    /// <param name="_input">Date input value; use today's date, if input is empty.</param>

    /// <returns>Returns the date input value in the string format YYYYMMDD.</returns>

    public static str YYYYMMDD(Date _input = DateTimeUtil::date(DateTimeUtil::getSystemDateTime()))

    {

        str dateString;

        

        dateString  = date2str(_input,

                                321,

                                DateDay::Digits2,

                                DateSeparator::None,

                                DateMonth::Digits2,

                                DateSeparator::None,

                                DateYear::Digits4);


        return dateString;

    }


    /// <summary>

    /// Convert the time input value to the string format hhmmss.

    /// </summary>

    /// <param name="_input">Time input value; use the current time, if the input is empty.</param>

    /// <returns>Returns the time input value in the string format hhmmss.</returns>

    public static str hhmmss(TimeOfDay _input = DateTimeUtil::time(DateTimeUtil::getSystemDateTime()))

    {

        str timeValue;

        str timeString;

        

        timeValue   = time2str( _input,

                            TimeSeparator::Dot,

                            TimeFormat::Hour24);


        timeString  =   substr(timeValue,1,2) +

                    substr(timeValue,4,2) +

                    substr(timeValue,7,2);


        return  timeString;

    }


    /// <summary>

    /// Convert the date and time input to the string format YYYYMMDD_hhmmss.

    /// </summary>

    /// <param name="_input">Date and time input value; use the current system date and time, if the input is empty.</param>

    /// <returns>Returns the date and time input in the string format YYYYMMDD_hhmmss.</returns>

    public static str YYYYMMDD_hhmmss(utcdatetime _dateTime = DateTimeUtil::getSystemDateTime())

    {

        Date        dateValue;

        TimeOfDay   timeValue;

        

        dateValue = DateTimeUtil::date(_dateTime);

        timeValue = DateTimeUtil::time(_dateTime);


        return strfmt('%1_%2', Global::YYYYMMDD(dateValue), Global::hhmmss(timeValue));

    }


    /// <summary>

    /// Convert the date and time input to the string format YYMMDD.

    /// </summary>

    /// <param name="_input">Date and time input value; use the current system date and time, if the input is empty.</param>

    /// <returns>Returns the date and time input in the string format YYMMDD.</returns>

    static str YYMMDD(Date _input = DateTimeUtil::date(DateTimeUtil::getSystemDateTime()))

    {

        str dateString;

        

        dateString  = date2str(_input,

                                321,

                                DateDay::Digits2,

                                DateSeparator::None,

                                DateMonth::Digits2,

                                DateSeparator::None,

                                DateYear::Digits2);


        return dateString;

    }


    public static date getCompanyDate(utcdatetime _input = DateTimeUtil::utcNow())

    {

        return DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(_input, DateTimeUtil::getCompanyTimeZone()));

    }


    static str removeTabLineBreaks(str _input)

    {

        #File


        _input  = strreplace(_input, #delimiterEnter, #delimiterSpace);

        _input  = strreplace(_input, #delimiterTab, #delimiterSpace);

        _input  = strreplace(_input, #delimiterCRLF, #delimiterSpace);


        return _input;

    }


public static void setVisibilityForControls(FormRun _formrun, List _listOfControls, boolean isVisible)

    {

        if (_formrun && _listOfControls && !_listOfControls.empty())

        {

            ListIterator iterator = new ListIterator(_listOfControls);

            while(iterator.more())

            {

                FormControlName controlName = iterator.value();

                FormControl control = Global::getFormControl(_formrun, controlName);

                if (Control)

                {

                    control.visible(isVisible);

                }


                iterator.next();

            }

        }

    }


    private static FormControl getFormControl(FormRun _formrun, FormControlName _controlName)

    {

        return _formrun != null ? _formrun.control(_formrun.controlId(_controlName)) : null;

    }



No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...