Purpose:
The purpose of this document is to demonstrate how to how to update record in form through X++ based on a business logic.
Ex: user wants to update particular field for old and newly created records based on code, here im using update process through simple batch process
Product:
Dynamics 365 for Finance and Operations.
Development approach:
Customization through CODE, we need update records , for this created controller and service classes
Development:
created controller and service classes
code below
AmountUpdateController class
{
public static SysOperationController construct(Args _args)
{
SysOperationController controller;
controller = new AmountUpdateController(
classStr(AmountUpdateService),
methodStr(AmountUpdateService, process),
SysOperationExecutionMode::Synchronous);
controller.parmArgs(_args);
return controller;
}
/// <summary>
///
/// </summary>
/// <param name = "_args"></param>
public static void main(Args _args)
{
AmountUpdateController ::construct(_args).startOperation();
}
/// <summary>
/// Specifies if the batch task is retryable for transient exceptions or not.
/// </summary>
/// <returns>
/// If true is returned, the batch task is retryable, otherwise it is not.
/// </returns>
[Hookable(false)]
final boolean isRetryable()
{
return true;
}
}
AmountUpdateService class
{
public void process()
{
GeneralJournalEntry entry;
while select * from entry
where entry.CustomAmount != ''"
{
ttsbegin;
entry.CustomAmount = "Your values";
entry.update();
ttscommit;
}
Info("Update Transaction Type job finished");
}
}
Once class and logic preparation completed we can use Menuitem to attach our class, and enable and configure recurrences, so that it will loop all the records where our custom field is empty and fill the data.
Comments
Post a Comment