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