web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to activate ModifedFields method when value assigned using x++ ?

(0) ShareShare
ReportReport
Posted on by 596

Hi guys,

I'm creating sales order using X , and in one of the field assignment, there is one task that extend the ModifiedField function of the table. The extension is on another class of EventHandler.

The detail is like this:

1. My code create Sales Order and the fields are RevRecContractStartDate and RevRecContractEndDate. This is some fields when we activate Revenue Recognition feature.

2. If it is manual SO creation (from UI), when we input these two fields, it is call an eventhandler class -> RevRecSalesTableFormEventHandler.

3. Inside this event handler there is function that extend ModifiedField event type which in its next step calling this class own "protected" method -> setRevenueSchedule(SalesLine _salesLine)

Question is how to use this method in my code ?

The event handler ModifiedField method is like this : 

[FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, RevRecContractStartDate), FormDataFieldEventType::Modified),
    SuppressBPWarning('BPParameterNotUsed', 'Parameter required by the event interface.')]
    public static void revRecContractStartDateOnModified(FormDataObject _sender, FormDataFieldEventArgs _e)
    {
        if (RevRecEnableFeature::isEnabled())
        {
            SalesLine salesLine = _sender.datasource().cursor();

            if (salesLine.RevRecContractEndDate && salesLine.RevRecContractStartDate)
            {
                RevRecSalesTableFormEventHandler::setRevenueSchedule(salesLine);
            }
            else if (!salesLine.RevRecContractEndDate && !salesLine.RevRecContractStartDate)
            {
                salesLine.RevRecOccurrences = 0;
            }
        }
    }

If you can see, in the middle, when field RevRecContractEndDate and RevRecContractStartDate is not empty it will call a method setRevenueSchedule.

and the protected method in that class is this one:

protected static void setRevenueSchedule(SalesLine _salesLine)
    {
        RevRecRevenueSchedule salesLineRevenueSchedule = RevRecRevenueSchedule::find(_salesLine.RevRecRevenueScheduleID);

        _salesLine.RevRecOccurrences = 
            SalesLine::revRecCalculateOccurrences(
                _salesLine.RevRecContractStartDate, 
                _salesLine.RevRecContractEndDate,
                salesLineRevenueSchedule.RecognitionBasis);

        RevRecRevenueSchedule revenueSchedule = RevRecRevenueSchedule::findbyOccurences(_salesLine.RevRecOccurrences);

        if (revenueSchedule && !RevRecSalesTableFormEventHandler::existingRevenueScheduleOccurencesMatch(revenueSchedule.Occurrences, _salesLine.RevRecRevenueScheduleID))
        {
            _salesLine.RevRecRevenueScheduleId = revenueSchedule.RevenueScheduleID;
        }
        else if (!revenueSchedule)
        {
            _salesLine.RevRecRevenueScheduleId = null;
            warning("@RevenueRecognition:RevenueScheduleRemoved");
        }

        RevRecUtil::validateRevenueScheduleId(_salesLine);
    }

and my class for creation of Sales Order is pretty simple, when insert SalesLine, after assign all the necessary value, I'm using salesLine.createLine(true, false, false, true, false, false) function.

The issue I'm having right now is if I directly use the same method : RevRecSalesTableFormEventHandler::setRevenueSchedule(salesLine); I will have error ->


"Error Method 'setRevenueSchedule' is protected and can be called only from methods in 'RevRecSalesTableFormEventHandler', or from classes or tables that derive from 'RevRecSalesTableFormEventHandler'. "

Thanks

  • Suggested answer
    Komi Siabi Profile Picture
    13,253 Most Valuable Professional on at

    Hello Lars Volt,

    To call ModifedField method without input from the interface, you can try this.

    salesLine.modifiedFieldValue(fieldstr(salesLine,yourFieldName));

  • Voltes Profile Picture
    596 on at

    Hi Komi,

    thanks, it works, but may I know why this ModifiledField does not go through the extension as well ? unless I wrongly trace it in debugging mode, it seems it is not calling this class RevRecSalesTableFormEventHandler, this one is an EventHandler class specific when we use Revenue Recognition module ->

    pastedimage1680589214648v1.png

    So it can not call the standard method inside, which is the RevRecSalesTableFormEventHandler::setRevenueSchedule(salesLine); this function I need it to get the correct Revenue Schedule Id from Start date and End Date.

    The modified method in that Event Handler, I put in previous thread.

    Thanks,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 320 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 210

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans