web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,049 Most Valuable Professional on at
    RE: How to activate ModifedFields method when value assigned using x++ ?

    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
    RE: How to activate ModifedFields method when value assigned using x++ ?

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 765 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 743

#3
Sumit Singh Profile Picture

Sumit Singh 551

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans