81) How to use the signature using Disposable context ( Store value in global catch)
I had a scenario where I need to Store the value in the gobal value and use it some where .
The challenge is that i need to store the value because there is standard process going and in between i need to put my code
Step 1- Create a class that will hold the global caches
public final class AvaEntWorkOrderAdjustParameter implements System.IDisposable
{
private static AvaEntWorkOrderAdjustParameter instance;
Public str formCallerName;
Public boolean ExpectedEndGroup;
Public boolean MoveExpectedEndGroup;
public EntAssetWorkOrderTable callerWorkOrderTable;
public NumberOfDays MoveExpectedEnd;
public EntAssetExpectedEnd ExpectedEnd;
protected void new()
{
if (instance)
{
throw Error(Error::wrongUseOfFunction(funcName()));
}
instance = this;
formCallerName = "";
ExpectedEndGroup = NoYes::No;
MoveExpectedEndGroup = NoYes::No;
MoveExpectedEnd = 0;
ExpectedEnd = utcDateTimeNull();
}
public static AvaEntWorkOrderAdjustParameter construct()
{
return new AvaEntWorkOrderAdjustParameter();
}
/// <summary>
/// Disposes of the current instance of this class.
/// </summary>
public void dispose()
{
instance = null;
}
/// <summary>
/// Gets the current instance of this class.
/// </summary>
/// <returns>The current instance of this class.</returns>
public static AvaEntWorkOrderAdjustParameter current()
{
return instance;
}
}
+=====================================================================
Step 2 :- Create a extension of the form where we need to store the value
public void closeOk()
{
AvaEntWorkOrderAdjustParameter avaEntWorkOrderAdjustParameter;
DialogButton dialogButton;
boolean createSeqWorkOrder = EntAssetMaintenancePlan::find(AvaEntAssetMaintenanceProgram::findRecId(callerWorkOrderTable.AvaMaintenanceProgram).MaintenancePlan).AvaSequentialWorkOrderDate;
if( callerFormName == formStr(AvaEntAssetMaintenanceProgram) && ExpectedEndGroup.optionValue() & this.validateFields() && createSeqWorkOrder)
{
if((MoveExpectedEnd.value() >= 0) && (ExpectedEnd.dateTimeValue() >= callerWorkOrderTable.ExpectedEnd))
{
dialogButton = Box::yesNo("@AvaTransMountain:AvaWorkorderDateUpdateDIalog_Label", DialogButton::Yes, "@AvaTransMountain:AvaWorkorderUpdate_Label");
if(dialogButton == DialogButton::Yes)
{
avaEntWorkOrderAdjustParameter = AvaEntWorkOrderAdjustParameter::construct();
avaEntWorkOrderAdjustParameter.formCallerName = callerFormName;
avaEntWorkOrderAdjustParameter.ExpectedEndGroup = ExpectedEndGroup.optionvalue();
avaEntWorkOrderAdjustParameter.MoveExpectedEndGroup = MoveExpectedEndGroup.optionvalue();
avaEntWorkOrderAdjustParameter.callerWorkOrderTable = callerWorkOrderTable;
avaEntWorkOrderAdjustParameter.MoveExpectedEnd = MoveExpectedEnd.value();
avaEntWorkOrderAdjustParameter.ExpectedEnd = ExpectedEnd.dateTimeValue();
}
}
}
next closeOk();
if (avaEntWorkOrderAdjustParameter::current())
{
avaEntWorkOrderAdjustParameter.dispose();
info("@AvaTransMountain:AvaDatesUpdate_Infolog");
}
}
========================================================================
Step 3 :- Create a extension of the class where we want to use this global cache value and release it here
[ExtensionOf(classStr(EntAssetWorkOrderTableAdjust))]
final class AvaEntAssetWorkOrderTableAdjustCls_Extension
{
private EntAssetWorkOrderTable avaWorkOrderTable;
private int avaWorkOrderCount;
private int adjustedDays;
private int workOrderLineAdjustedDays;
#define.MaxWorkOrders(30)
public void run()
{
AvaEntWorkOrderAdjustParameter EntWorkOrderAdjustParameter = AvaEntWorkOrderAdjustParameter::current();
EntAssetExpectedStart expectedEndOrig;
if (EntWorkOrderAdjustParameter)
{
expectedEndOrig = EntWorkOrderAdjustParameter.callerWorkOrderTable.ExpectedEnd;
}
next run();
avaWorkOrderCount++;
if (EntWorkOrderAdjustParameter)
{
if(!avaWorkOrderTable)
{
avaWorkOrderTable = EntWorkOrderAdjustParameter.callerWorkOrderTable;
avaWorkOrderTable.reread();
EntAssetExpectedStart expectedEndCurrent = avaWorkOrderTable.ExpectedEnd;
TransDate NewEndDate = DateTimeUtil::date(expectedEndCurrent);
TransDate oldEndDate = DateTimeUtil::date(expectedEndOrig);
adjustedDays = (NewEndDate - oldEndDate);
}
if (adjustedDays > 0)
{
EntAssetWorkOrderTable workOrderTableNextLocal;
TransDate NewEndDateWorkOrderLine;
TransDate oldEndDateWorkOrderLine;
avaWorkOrderTable.reread();
select firstonly forupdate workOrderTableNextLocal
order by workOrderTableNextLocal.WorkOrderId
where workOrderTableNextLocal.AvaMaintenanceProgram == avaWorkOrderTable.AvaMaintenanceProgram
&& workOrderTableNextLocal.WorkOrderId > avaWorkOrderTable.WorkOrderId;
if (workOrderTableNextLocal && avaWorkOrderCount<#MaxWorkOrders)
{
if(EntWorkOrderAdjustParameter.MoveExpectedEndGroup)
{
NewEndDateWorkOrderLine = DateTimeUtil::date(avaWorkOrderTable.ExpectedEnd);
oldEndDateWorkOrderLine = DateTimeUtil::date(workOrderTableNextLocal.ExpectedStart);
workOrderLineAdjustedDays = (NewEndDateWorkOrderLine - oldEndDateWorkOrderLine);
moveExpectedStart = true;
moveExpectedStartDays = workOrderLineAdjustedDays;//adjustedDays;
moveExpectedEnd = true;
moveExpectedEndDays = workOrderLineAdjustedDays;//adjustedDays;
}
else
{
NewEndDateWorkOrderLine = DateTimeUtil::date(avaWorkOrderTable.ExpectedEnd);
oldEndDateWorkOrderLine = DateTimeUtil::date(workOrderTableNextLocal.ExpectedStart);
workOrderLineAdjustedDays = (NewEndDateWorkOrderLine - oldEndDateWorkOrderLine);
newExpectedStart = true;
expectedStart = avaWorkOrderTable.ExpectedEnd;//DateTimeUtil::addDays(avaWorkOrderTable.ExpectedStart, adjustedDays);
newExpectedEnd = true;
expectedEnd = DateTimeUtil::addDays(workOrderTableNextLocal.ExpectedEnd, workOrderLineAdjustedDays);
}
workOrderSet = new Set(Types::Int64);
workOrderSet.add(workOrderTableNextLocal.RecId);
newServiceLevel = false;
newResponsible = false;
avaWorkOrderTable.data(workOrderTableNextLocal);
this.run();
}
}
}
}
}
========================================================================
Please also find the demo attached Document for this :-
Reference link
- https://community.dynamics.com/365/financeandoperations/b/365operationswithsukrut/posts/extending-method-signature-using-disposable-context
Comments
Post a Comment